Why does this code generate a NotSupportedException?

Posted by edg on Stack Overflow See other posts from Stack Overflow or by edg
Published on 2010-04-27T08:19:37Z Indexed on 2010/04/27 8:23 UTC
Read the original article Hit count: 285

This is fine

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

and this is fine

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

So why does this throw 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();

© Stack Overflow or respective owner

Related posts about linq-to-entities

Related posts about notsupportedexception