entity framework 4 - EF 4: Referencing Non-Scalar Variables Not Supported -
i'm using code first , trying simple query, on list property see if contains string in filtering list. running problems. simplicity assume following.
public class person { public list<string> favoritecolors { get; set; } } //now code. create , add dbcontext var person = new person{ favoritecolors = new list<string>{ "green", "blue"} }; dbcontext.persons.add(person); mydatabasecontext.savechanges(); //build var filterby = new list<string>{ "purple", "green" }; var matches = dbcontext.persons.asqueryable(); matches = p in matches color in p.favoritecolors filterby.contains(color) select p;
the option considering transforming json serialized string since can perform contains call if favoritecolors string. alternatively, can go overboard , create "color" entity thats heavy weight. unfortunately enums not supported.
i think problem not collection, reference matches
.
var matches = dbcontext.persons.asqueryable(); matches = p in matches color in p.favoritecolors filterby.contains(color) select p;
if check out known issues , considerations ef4 more or less case mentioned.
referencing non-scalar variables, such entity, in query not supported. when such query executes, notsupportedexception exception thrown message states "unable create constant value of type entitytype.
also note says referencing collection of scalar variables is supported (that's new in ef 4 imo).
having said following should work (can't try out right now):
matches = p in dbcontext.persons color in p.favoritecolors filterby.contains(color) select p;
Comments
Post a Comment