Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

The type '...' cannot be used as type parameter 'TContext' in the generic type or method 'System.ServiceModel.DomainServices.EntityFramework.LinqToEntitiesDomainService<TContext>'.

4.1.0.0 버전의 EntityFramework을 Nuget을 통해 업그레이드했더니 컴파일 에러가 꽤나 발생하는 군요. ^^;

대부분의 경우 네임스페이스가 바뀌는 바람에 발생한 것이어서 아래 정도의 신규 네임스페이스만 추가해주면 거의 잡혔는데,

using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Core.Objects.DataClasses;

유독 한 개의 에러는 꿋꿋하게 살아남았습니다.

The type 'Test40.WebSiteTest.UnitTestDB2Entities' cannot be used as type parameter 'TContext' in the generic type or method 'System.ServiceModel.DomainServices.EntityFramework.LinqToEntitiesDomainService<TContext>'. There is no implicit reference conversion from 'Test40.WebSiteTest.UnitTestDB2Entities' to 'System.Data.Objects.ObjectContext'.


오류가 발생한 소스 코드는 이렇고,

[EnableClientAccess()]
public class MyODataDomainService : LinqToEntitiesDomainService<UnitTestDB2Entities>
{
	// ...[생략]...
}

LinqToEntitiesDomainService의 정의를 찾아가 보니 다음과 같은 클래스입니다.

// C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.DomainServices.EntityFramework\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.DomainServices.EntityFramework.dll

[LinqToEntitiesDomainServiceDescriptionProvider]
public abstract class LinqToEntitiesDomainService<TContext> : DomainService where TContext: System.Data.Objects.ObjectContext, new()
{
	// ...[생략]...
}

그러니까, LinqToEntitiesDomainService에 전달하는 UnitTestDB2Entities 클래스가 "where TContext: System.Data.Objects.ObjectContext" 조건에 맞지 않는다는 것입니다.

그래서 제가 정의한 UnitTestDB2Entities 클래스를 봤는데,

// MyTaskModel.Designer.cs

using System;
using System.ComponentModel;
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Core.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;

[assembly: EdmSchemaAttribute()]
namespace Jennifer40.WebSiteTest.WCFs
{
    public partial class UnitTestDB2Entities : ObjectContext
    {
	// ...[생략]...
	}
}

여기서의 ObjectContext는 System.Data.Entity.Core.Objects 네임스페이스에 있는 ObjectContext였습니다. 왜 이런 일이 발생했냐면? 컴파일 오류가 나길래 "Ctrl + ." 키를 눌러 자동으로 네임스페이스를 추가하려 했고 2개의 선택 사항(System.Data.Entity.Core.Objects, System.Data.Objects)중에 무심코 첫 번째 항목을 선택했던 것입니다.

사실, 원래의 MyTaskModel.Designer.cs 파일은 MyTaskModel.edmx 정의에서 자동 생성되는 파일이었습니다. 그래서 단순히 EntityFramework을 업그레이드 한 후 각종 .edmx 파일을 찾아서 새롭게 저장만 해주면 자동으로 System.Data.Objects 네임스페이스를 잡았을 텐데, 제가 임의로 했기 때문에 이런 오류가 발생한 것이었습니다.

따라서 EntityFramework을 구 버전에서 신 버전으로 마이그레이션 할 때는 다음과 같은 2단계 절차를 따르는 것이 가장 좋습니다.

  1. 우선, .edmx 파일들을 찾아서 명시적인 저장을 한다.
  2. 나머지 오류가 발생하는 것들은 새로운 네임스페이스를 적용해 준다.

끝!




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 6/26/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 76  77  78  79  [80]  81  82  83  84  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11640정성태8/3/201814794Graphics: 18. Unity - World matrix(unity_ObjectToWorld)로부터 Position, Rotation, Scale 값을 복원하는 방법파일 다운로드1
11639정성태8/2/201812382디버깅 기술: 117. windbg - 덤프 파일로부터 추출한 DLL을 참조하는 방법
11638정성태8/2/201810750오류 유형: 473. windbg - 덤프 파일로부터 추출한 DLL 참조 시 "Resolved file has a bad image, no metadata, or is otherwise inaccessible." 빌드 오류
11637정성태8/1/201814501Graphics: 17. Unity - World matrix(unity_ObjectToWorld)로부터 TRS(이동/회전/크기) 행렬로 복원하는 방법파일 다운로드1
11636정성태8/1/201821855Graphics: 16. 3D 공간에서 두 점이 이루는 각도 구하기파일 다운로드1
11635정성태8/1/201811466오류 유형: 472. C# 컴파일 오류 - Your project is not referencing the ".NETFramework,Version=v3.5" framework.
11634정성태8/1/201813394.NET Framework: 790. .NET Thread 상태가 Cooperative일 때 GC hang 현상 재현 방법파일 다운로드1
11633정성태7/29/201817805Graphics: 15. Unity - shader의 World matrix(unity_ObjectToWorld)를 수작업으로 구성 [2]파일 다운로드1
11632정성태7/28/201820441Graphics: 14. C# - Unity에서 캐릭터가 바라보는 방향을 기준으로 카메라의 위치 이동 및 회전하는 방법
11631정성태7/27/201821605Graphics: 13. Unity로 실습하는 Shader (9) - 투명 배경이 있는 텍스처 입히기 [1]
11630정성태7/27/201816591개발 환경 구성: 391. (GitHub 등과 직접 연동해) 소스 코드 디버깅을 쉽게 해 주는 SourceLink [3]
11629정성태7/26/201815138.NET Framework: 789. C# 컴파일 옵션 - Check for arithmetic overflow/underflow [2]
11628정성태7/25/201817912Graphics: 12. Unity로 실습하는 Shader (8) - 다중 패스(Multi-Pass Shader)
11627정성태7/25/201812420개발 환경 구성: 390. C# - 컴파일러 옵션 OSS signing / Public Signing
11626정성태7/25/201811569오류 유형: 471. .C++ 함수를 const로 바꾼 경우 C2440 컴파일 오류가 발생한다면?
11625정성태7/24/201810467Math: 49. GeoGebra 기하 (25) - 타원의 중심점 찾기파일 다운로드1
11624정성태7/24/201813803개발 환경 구성: 389. C# - 재현 가능한 빌드(reproducible builds) == Deterministic builds [4]
11623정성태7/24/201813646Math: 48. C# - 가우시안 함수의 이산형(discrete) 커널 값 생성파일 다운로드1
11622정성태7/23/201814193개발 환경 구성: 388. Windows 환경에서 Octave 패키지 설치하는 방법
11621정성태7/23/201812155VC++: 127. 멤버 함수에 대한 포인터를 외부에서 호출하는 방법파일 다운로드1
11620정성태7/22/201815294Graphics: 11. Unity로 실습하는 Shader (7) - Blur (평균값, 가우스, 중간값) 필터 [1]파일 다운로드1
11619정성태7/21/201813890Graphics: 10. Unity로 실습하는 Shader (6) - Mosaic Shading
11618정성태7/20/201812223개발 환경 구성: 387. 삼성 오디세이(Odyssey) 노트북의 운영체제를 새로 설치하는 방법
11617정성태7/20/201812457Team Foundation Server: 50. TFS 소스 코드 관리 기능 (5) - "Rollback", "Rollback Entire Changeset"
11616정성태7/17/201812106Graphics: 9. Unity Shader - 전역 변수의 초기화
11615정성태7/17/201815871.NET Framework: 788. RawInput을 이용한 키보드/마우스 입력 모니터링파일 다운로드1
... 76  77  78  79  [80]  81  82  83  84  85  86  87  88  89  90  ...