c# - LINQ to Entities, Where Any In -


how write 'where in' in linq entity?

here model :

class chair {     public int id { get; set; }     public int tableid { get; set; }     public table table { get; set; }  }  class table {     public int id { get; set; }      public icollection<chair> chairs { get; set; }     public icollection<category> categories { get; set; }     public table()     {         chairs = new list<chair>();         categories = new list<category>();     } }  class category {     public int id { get; set; }     public icollection<table> tables { get; set; } } 

i got simple list of category :

list<category> mycategories = new list<category>(c,d,e); 

i want chairs belongs table got 1 of category mycategories list. thats im trying :

var result =  ctx.chairs.where(x => x.table.categories.any(y => mycategories.any(z => z.id == y.id))).tolist(); 

i think ok error :

"unable create constant value of type 'consoleapplication1.category'. primitive types or enumeration types supported in context"

try compare in-memory categories ids collection, instead of categories collection.

var mycategoriesids = mycategories.select(c => c.id).toarray();  var result =     context.chairs         .where(             x => x.table.categories.any(                 y => mycategoriesids.contains(y.id)))         .tolist(); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -