1
  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]

Sybren
  • 1,071
  • 3
  • 17
  • 51

2 Answers2

1

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

Community
  • 1
  • 1
Chris_
  • 716
  • 8
  • 11
1

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.

Antoine Pelletier
  • 3,164
  • 3
  • 40
  • 62