데이터베이스의 모든 레코드를 검색하는 대리인을 만들고 있습니다. 나는 다른 프로젝트에서 이와 같은 방식으로 사용했지만, 어떤 이유로 이번에는 오류가 발생합니다.컴파일 된 쿼리가 ObjectContext에 대한 암시 적 참조 변환이 없습니다.
단계를 놓쳤습니까? 왜이 오류가 나타나는지 잘 모르겠습니다.
코드
public static readonly Func<CodySolutionEntities, IQueryable<Album>> SelectAlbums =
CompiledQuery.Compile<CodySolutionEntities, IQueryable<Album>>(
query => from q in query.Albums.Include("Photo")
select q);
오류
가 오류 1 유형 'CodyData.Diagram.CodySolutionEntities가'형으로 사용할 수 없습니다가 parameter 'TArg0' in the generic type or method 'System.Data.Objects.CompiledQuery.Compile<TArg0,TResult>(System.Linq.Expressions.Expression<System.Func<TArg0,TResult>>)'. There is no implicit reference conversion from 'CodyData.Diagram.CodySolutionEntities' to 'System.Data.Objects.ObjectContext'. C:\Users\Cody\Documents\CMBS\CodySolution\CodyData\Delegates\PhotoDelegates.cs 13 13 CodyData
'DbContext'를 사용하여 내가하려는 일을 수행하는 동등한 방법은 무엇입니까? – Cody
그게 문제 야. ** DbContext와 CompiledQuery를 함께 사용할 수 없다. 참조 : http://stackoverflow.com/a/6731102/1289454. 컴파일되지 않은 쿼리를 붙이시겠습니까? 'using (var context = new CodySolutionEntities()) {var albums = context.Albums.Include (a => a.Photos); // ...}' – gowansg