c# - How to make LINQ to multiple tables -


i have 2 ef entities: client , benefit. (in database connected in intermediary table: "clientsbenefits", if it's important), connected them in intermediary class "clientindexdata", adviced on asp.net guides.

could advice me how use linq search clients without benefits?

i know, how using sql, surprised @ linq specific syntax , cannot more complex casual .where (i => i.name == null) :( trying smth that:

clients.clients = clients.clients.where(i => i.benefits == null) 

where clients variable is:

var clients = new clientindexdata(); clients.clients = db.clients             .include(i => i.schedules.select(c => c.fintessarea))             .include(i => i.paids)             .include(i => i.benefits)             .include(i => i.tickets); if (benefitid != null)         {             viewbag.benefitid = benefitid.value;             clients.benefits = clients.clients.where(                 => i.Сlientidentificator == id.value).single().benefits;         }          .... 

and clientindexdata class is:

public class clientindexdata {     public ienumerable<client> clients { get; set; }     public ienumerable<benefit> benefits { get; set; }     public ienumerable<ticket> tickets { get; set; }     public ienumerable<paid> paids { get; set; }     public ienumerable<schedule> schedules { get; set; }  } 

i really thankful if advice me how count benefits (or tickets) each client (using groupby , count) using linq.

with linq orms try avoid joins , use navigation properties directly. write if objects in memory , connected regular object references , collections:

clients.clients.where(i => !i.benefits.any()) 

or, less nicely , slower on sql server:

clients.clients.where(i => i.benefits.count() == 0) 

note, linq database queries normal linq object queries. skill benefit in both case.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -