Tag: 编译查询

编译查询没有隐式引用转换为ObjectContext

我正在创建一个委托来检索数据库中的所有专辑记录。 我在另一个项目中使用了相同的方法,但由于某种原因我这次收到错误。 我错过了一步吗? 我不确定为什么会出现这个错误。 码 public static readonly Func<CodySolutionEntities, IQueryable> SelectAlbums = CompiledQuery.Compile<CodySolutionEntities, IQueryable>( 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(System.Linq.Expressions.Expression<System.Func>)’. 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用作类型parameter ‘TArg0’ in the generic type or method ‘System.Data.Objects.CompiledQuery.Compile(System.Linq.Expressions.Expression<System.Func>)’. There […]

我什么时候应该使用CompiledQuery?

我有一张桌子: — Tag ID | Name ———– 1 | c# 2 | linq 3 | entity-framework 我有一个类将有以下方法: IEnumerable GetAll(); IEnumerable GetByName(); 在这种情况下我应该使用编译的查询吗? static readonly Func<Entities, IEnumerable> AllTags = CompiledQuery.Compile<Entities, IEnumerable> ( e => e.Tags ); 然后我的GetByName方法将是: IEnumerable GetByName(string name) { using (var db = new Entities()) { return AllTags(db).Where(t => t.Name.Contains(name)).ToList(); } } 它生成一个SELECT ID, […]