简体   繁体   中英

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]

The problem you are running into is that Entity Framework can't actually run your C# code as part of its query.

You're going have to restructure to remove "WhereSelectedAcademicYear()" into its own area as it is not convertible to a SQL statement. Just keep in mind, in the background it always needs to be able to convert what you put into LINQ into a sql statement.

Here is the same question answered here: LINQ to Entities does not recognize the method

Linq to Entity does not recognize the function, of course.

Some complexes function cannot be put inside the parenthesis of a linq to Entity function.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM