ADO.net实体模型框架中的CompiledQuery
public static Func<ReviewEntities, int, IQueryable<ProjTeamMemberDetails>>
GetTeamMembersByTeamId = CompiledQuery.Compile((ReviewEntities context, int teamId)
=> from tp in context.TeamPlayers
join t in context.Teams on tp.TeamId equals t.ID
join emp in context.Employees on tp.EmployeeId equals emp.ID
where tp.TeamId == teamId && emp.IsActive == true
orderby emp.JoiningDate
select new ProjTeamMemberDetails
{
EmployeeName = emp.FirstName + " " + emp.LastName,
Email = emp.Email,
Designation = context.Designations.FirstOrDefault(s => s.ID == emp.DesignationId).Name,
NIC = emp.NIC,
JoiningDate = emp.JoiningDate,
EmployeeID = emp.ID
})
这是我为ADO.Net实体模型框架创建编译查询的代码。在语法 CompiledQuery.Complie((ReviewEntities 中,有一个奇怪的错误,说是
类型'ReviewEntities'不能是在泛型类型或方法'System.Data.Linq.CompiledQuery.Compile(System.Linq.Expressions.Expression>)'中用作类型参数'TArg0'。没有从'ReviewEntities'到'System.Data的隐式引用转换.Linq.DataContext'。
我无法弄清楚为什么这会产生错误。它不接受第一个参数这是DataContext。
编译查询是否适用于ADO.Net实体模型?
任意帮助将受到高度赞赏。
This is my code to create a compiled query for ADO.Net entity model framework. In the syntax "CompiledQuery.Complie((ReviewEntities", there is a strange error which say's
"The type 'ReviewEntities' cannot be used as type parameter 'TArg0' in the generic type or method 'System.Data.Linq.CompiledQuery.Compile(System.Linq.Expressions.Expression>)'. There is no implicit reference conversion from 'ReviewEntities' to 'System.Data.Linq.DataContext'."
I am unable to figure this out why this is creating error. It is not accepting first parameter that is DataContext.
Does Compiled query works in ADO.Net entity model or not?
Any help will be highly appreciated.
您可能正在使用System.Data.Linq的CompiledQuery。请改用System.Data.Objects。
You are probably using the CompiledQuery of System.Data.Linq. Use System.Data.Objects instead.
可能你正在使用DbContext.4.0版中的编译LINQ查询只能使用ObjectContext。不幸的是,对DbContext的支持和自动缓存功能在更高版本中发布。
参考: http://stackoverflow.com / a / 14290697 [ ^ ]
Probably you are using DbContext. Compiled LINQ queries in 4.0 works with only ObjectContext. There was no support to DbContext unfortunately and auto-caching feature is released in later versions.
Refer: http://stackoverflow.com/a/14290697[^]