[英]Entity Framework IQueryable Query String Error
var academicInfo = Connection.Student_AcademicInfo.WhereSelectedAcademicYear();
var sub = (from s in Connection.Students
from si in academicInfo
where s.RecordId == si.ParentRecordId
&& si.InstituteId == UserData.InstituteId
select si);
if I use this method no error but 如果我使用这种方法没有错误,但是
var sub = (from s in Connection.Students
from si in Connection.Student_AcademicInfo.WhereSelectedAcademicYear()
where s.RecordId == si.ParentRecordId
&& si.InstituteId == UserData.InstituteId
select si);
if I user this method i see error 如果我使用此方法,我会看到错误
Error Additional information: LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[ImsBase.Core.Database.Student_AcademicInfo] WhereSelectedAcademicYear[Student_AcademicInfo]
错误附加信息:LINQ to Entities无法识别方法'System.Linq.IQueryable`1 [ImsBase.Core.Database.Student_AcademicInfo] WhereSelectedAcademicYear [Student_AcademicInfo]
The problem you are running into is that Entity Framework can't actually run your C# code as part of its query. 您遇到的问题是,实体框架实际上无法在查询中运行C#代码。
You're going have to restructure to remove "WhereSelectedAcademicYear()" into its own area as it is not convertible to a SQL statement. 您将必须进行重组以将“ WhereSelectedAcademicYear()”删除到其自己的区域中,因为它不能转换为SQL语句。 Just keep in mind, in the background it always needs to be able to convert what you put into LINQ into a sql statement.
请记住,在后台,它始终需要能够将您放入LINQ的内容转换为sql语句。
Here is the same question answered here: LINQ to Entities does not recognize the method 这是在此处回答的相同问题: LINQ to Entities无法识别该方法
Linq to Entity does not recognize the function, of course. 当然,Linq to Entity无法识别该功能。
Some complexes function cannot be put inside the parenthesis of a linq to Entity function. 某些复杂函数不能放在linq to Entity函数的括号内。
To solve this, you have to put the result of the complex function into a simple var and then make your query with the result, just like you did in your first exemple. 为了解决这个问题,您必须将复杂函数的结果放入一个简单的var中,然后对结果进行查询,就像在第一个示例中所做的一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.