Why does this code throw a NotSupportedException?

Why does this throw a System.NotSupportedException ?

string foo(string f) { return f; }
string bar = "";
var item = (from f in myEntities.Beer
            where f.BeerName == foo(bar)
            select f).FirstOrDefault();

Edit: Here's an MSDN link that (kind of) explains things ...

Any method call in LINQ for query objects that is not explicitly mapped to a canonical function will result in a run-time NotSupportedException exception. For a list of CLR methods that map to canonical functions, see the CLR method for Canonical Function Mapping.

See also http://mosesofegypt.net/post/LINQ-to-Entities-what-is-not-supported.aspx

+3
source share
3 answers

EDIT: , , , foo(). , SQL.

- (, string.StartsWith), , foo - foo() - . SQL.

+9

, . IQueryable<> where (, , , LINQ SQL).

+1

. ToList() SingleOrDefault().

, , SQL- , foo(), .

+1

Source: https://habr.com/ru/post/1742951/


All Articles