简体   繁体   English

实体框架IQueryable查询字符串错误

[英]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.

相关问题 试图模拟可查询实体框架查询 - Trying to Mock IQueryable Entity Framework Query .NET &amp; Entity Framework : 使用 IQueryable 查询数据库 - .NET & Entity Framework : query database by using IQueryable 在实体框架中将LINQ动态查询转换为IQueryable - Converting a LINQ dynamic query to IQueryable in Entity Framework 在实体框架 6 SelectMany to Join 选项中查询抛出错误源 IQueryable 未实现 IDbAsyncEnumerable<MyModel> - In entity framework 6 SelectMany to Join option for query throwing error The source IQueryable doesn't implement IDbAsyncEnumerable<MyModel> 实体框架IQueryable,带有2个查询 - Entity Framework IQueryable, with 2 queries 使用实体框架运行IQueryable - Run an IQueryable with Entity Framework 实体框架IQueryable扩展方法不能用作子查询 - Entity framework IQueryable extension methods do not work as a sub query 如何在实体框架中将查询脚本用作IQueryable或DBSet - How to use query scripts as IQueryable or DBSet in Entity Framework 使用 Entity Framework Core 5,如何嵌套查询并且仍然有 IQueryable? - With Entity Framework Core 5, how to nest a query and still have an IQueryable? 如何在Entity Framework 6中将SQL函数查询为IQueryable - How do you query SQL Function as IQueryable in Entity Framework 6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM