我有以下代码,我试图使用LINQ创建CompiledQuery。
public static Func<DataContext, int, object>
GetTeamMembersByTeamId = CompiledQuery.Compile<MazikReviewEntities, int, object>(
(context, 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
});
}
在CompiledQuery.Compile行中,我收到了一个错误,我的datacontext声明,
“类型'MazikGlobalReviewModel.MazikReviewEntities'不能在泛型类型或方法'System.Data.Linq.CompiledQuery.Compile(System.Linq.Expressions.Expression>)'中用作类型参数'TArg0'。没有隐式引用从'MazikGlobalReviewModel.MazikReviewEntities'转换为'System.Data.Linq.DataContext'。“
这个错误是什么以及如何解决这个问题?
我的朋友来自Mazik。如果你看一下错误就很清楚那里有什么问题。看看下面的代码。什么是代码中的datacontext和MazikReviewEntities。确保它们属于同一类型。
public static readonly Func<**MyDataContext**, int, IQueryable<tblSomething>> CompiledSelectSites =
CompiledQuery.Compile((**MyDataContext** c, int conf_id) =>
(from s in c.TblSomething
where s.ID == id
select site));
更多关注这个link。
这应该可以解决您的问题。