简体   繁体   中英

LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable`1

I am getting this error while using this IEquality comparer for intersection. Can somebody identify where I am doing it wrong?

Pleas ask if you need more information.

When you write LINQ to Entities, you must remember that eventually all of your LINQ expression is translated to SQL. So for every method call you make in that expression, you should think if there's a reasonable way to translate it to SQL.

Having that in mind, you can see that:

  1. SQL has no notion of .ToList() , which is probably the source of your current error. calls to .ToList() should be made at the end of the expression, as a way to "materialize" the query (ie make EF make the actual call to the database and return results).
  2. Your database knows nothing about C# interfaces. You can't expect any implementation of IEqualityComparer to be translatable to SQL.
  3. As @Dai has noted, you seem to be using too many joins. Make sure your model has the right navigation properties between entities, and use them.

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