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)
11976정성태7/4/20199059오류 유형: 553. (잘못 인증 한 후) 원격 git repo 재인증 시 "remote: HTTP Basic: Access denied" 오류 발생
11975정성태7/4/201917484개발 환경 구성: 448. Visual Studio Code에서 콘솔 응용 프로그램 개발 시 "입력"받는 방법
11974정성태7/4/201912856Linux: 22. "Visual Studio Code + Remote Development"로 윈도우 환경에서 리눅스(CentOS 7) C/C++ 개발
11973정성태7/4/201912147Linux: 21. 리눅스에서 공유 라이브러리가 로드되지 않는다면?
11972정성태7/3/201914874.NET Framework: 847. JAVA와 .NET 간의 AES 암호화 연동 [1]파일 다운로드1
11971정성태7/3/201912059개발 환경 구성: 447. Visual Studio Code에서 OpenCvSharp 개발 환경 구성
11970정성태7/2/201910429오류 유형: 552. 웹 브라우저에서 파일 다운로드 후 "Running security scan"이 끝나지 않는 문제
11969정성태7/2/201910807Math: 63. C# - 3층 구조의 신경망파일 다운로드1
11968정성태7/1/201917125오류 유형: 551. Visual Studio Code에서 Remote-SSH 연결 시 "Opening Remote..." 단계에서 진행되지 않는 문제 [1]
11967정성태7/1/201911385개발 환경 구성: 446. Synology NAS를 Windows 10에서 iSCSI로 연결하는 방법
11966정성태6/30/201910784Math: 62. 활성화 함수에 따른 뉴런의 출력을 그리드 맵으로 시각화파일 다운로드1
11965정성태6/30/201911571.NET Framework: 846. C# - 2차원 배열을 1차원 배열로 나열하는 확장 메서드파일 다운로드1
11964정성태6/30/201913066Linux: 20. C# - Linux에서의 Named Pipe를 이용한 통신
11963정성태6/29/201912786Linux: 19. C# - .NET Core Unix Domain Socket 사용 예제
11962정성태6/27/201910482Math: 61. C# - 로지스틱 회귀를 이용한 선형분리 불가능 문제의 분류파일 다운로드1
11961정성태6/27/201910041Graphics: 37. C# - PLplot - 출력 모음(Family File Output)
11960정성태6/27/201910822Graphics: 36. C# - PLplot의 16색 이상을 표현하는 방법과 subpage를 이용한 그리드 맵 표현
11959정성태6/27/201912043Graphics: 35. matplotlib와 PLplot의 한글 처리
11958정성태6/25/201916343Linux: 18. C# - .NET Core Console로 리눅스 daemon 프로그램 만드는 방법 [6]
11957정성태6/24/201915394Windows: 160. WMI 쿼리를 명령행에서 간단하게 수행하는 wmic.exe [2]
11956정성태6/24/201913370Linux: 17. CentOS 7에서 .NET Core Web App 실행 환경 구성 [1]
11955정성태6/20/201911661Math: 60. C# - 로지스틱 회귀를 이용한 분류파일 다운로드1
11954정성태6/20/201911148오류 유형: 550. scp - sudo: no tty present and no askpass program specified
11953정성태6/20/201910013오류 유형: 549. The library 'libhostpolicy.so' required to execute the application was not found in '...'
11952정성태6/20/201910797Linux: 16. 우분투, Centos의 Netbios 호스트 이름 풀이 방법
11951정성태6/20/201913585오류 유형: 548. scp 연결 시 "Permission denied" 오류 및 "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" 경고
... 61  62  63  64  65  [66]  67  68  69  70  71  72  73  74  75  ...