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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  [67]  68  69  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
11951정성태6/20/201913584오류 유형: 548. scp 연결 시 "Permission denied" 오류 및 "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" 경고
11950정성태6/18/201912345.NET Framework: 845. C# - 윈도우 작업 관리자와 리소스 모니터의 메모리 값을 구하는 방법
11949정성태6/18/20198838오류 유형: 547. CoreCLR Profiler 예제 프로젝트 빌드 시 컴파일 오류 유형
11948정성태6/17/201911098Linux: 15. 리눅스 환경의 Visual Studio Code에서 TFS 서버 연동
11947정성태6/17/201912342Linux: 14. 리눅스 환경에서 TFS 서버 연동
11946정성태6/17/201912957개발 환경 구성: 445. C# - MathNet으로 정규 분포를 따르는 데이터를 생성, PLplot으로 Histogram 표현파일 다운로드1
11945정성태6/17/201911359Linux: 13. node.js에서 syslog로 출력하는 방법
11944정성태6/16/201918138Linux: 12. Ubuntu 16.04/18.04에서 node.js 최신 버전 설치 방법
11943정성태6/15/201910930.NET Framework: 844. C# - 박싱과 언박싱 [1]
11942정성태6/13/201917398개발 환경 구성: 444. 로컬의 Visual Studio Code로 원격 리눅스 머신에 접속해 개발하는 방법 [1]
11941정성태6/13/201910711오류 유형: 546. "message NETSDK1057: You are using a preview version of .NET Core" 빌드 경고 없애는 방법
11940정성태6/13/201910598개발 환경 구성: 443. Visual Studio의 Connection Manager 기능(Remote SSH 관리)을 위한 명령행 도구파일 다운로드1
11939정성태6/13/20199687오류 유형: 545. Managed Debugging Assistant 'FatalExecutionEngineError'
11938정성태6/12/201911315Math: 59. C# - 웨이트 벡터 갱신식을 이용한 퍼셉트론 분류파일 다운로드1
11937정성태6/11/201917818개발 환경 구성: 442. .NET Core 3.0 preview 5를 이용해 Windows Forms/WPF 응용 프로그램 개발 [1]
11936정성태6/10/201911081Math: 58. C# - 최소 자승법의 1차, 2차 수렴 그래프 변화 확인 [2]파일 다운로드1
11935정성태6/9/201911764.NET Framework: 843. C# - PLplot 출력을 파일이 아닌 Window 화면으로 변경
11934정성태6/7/201912917VC++: 133. typedef struct와 타입 전방 선언으로 인한 C2371 오류파일 다운로드1
11933정성태6/7/201912981VC++: 132. enum 정의를 C++11의 enum class로 바꿀 때 유의할 사항파일 다운로드1
11932정성태6/7/201911522오류 유형: 544. C++ - fatal error C1017: invalid integer constant expression파일 다운로드1
11931정성태6/6/201911602개발 환경 구성: 441. C# - CairoSharp/GtkSharp 사용을 위한 프로젝트 구성 방법
11930정성태6/5/201912139.NET Framework: 842. .NET Reflection을 대체할 System.Reflection.Metadata 소개 [1]
11929정성태6/5/201911943.NET Framework: 841. Windows Forms/C# - 클립보드에 RTF 텍스트를 복사 및 확인하는 방법 [1]
11928정성태6/5/201910572오류 유형: 543. PowerShell 확장 설치 시 "Catalog file '[...].cat' is not found in the contents of the module" 오류 발생
11927정성태6/5/201911552스크립트: 15. PowerShell ISE의 스크립트를 복사 후 PPT/Word에 붙여 넣으면 한글이 깨지는 문제 [1]
11926정성태6/4/201913040오류 유형: 542. Visual Studio - pointer to incomplete class type is not allowed
... 61  62  63  64  65  66  [67]  68  69  70  71  72  73  74  75  ...