c# - Equivalent of 'WHERE columnname IN' SQL syntax in Entity Framework -


i have scenario

public class timesheet {     [key]     public int timesheetid { get; set; }     public string username { get; set; } }  public class approval {     [key]     public int approvalid { get; set; }     [index(isunique = true)]     [stringlength(450)]     public string approver { get; set; }     public virtual icollection<approvaldetail> details { get; set; } }  public class approvaldetail {     [key]     public int approvaldetailid { get; set; }     [stringlength(450)]     public string username { get; set; } } 

i want following syntax in ef.

select    *    timesheet    username in (select                    [ad].username                                    approval [a]                 inner join                     approvaldetail [ad] on [a].approvalid = [ad].approvalid                                    [a].approver = 'warheat1990') 

how achieve this?

update :

my repo

public ienumerable<timesheet> list() {     return _timesheet.asenumerable().tolist(); }  public ienumerable<timesheet> listbyusername(string username) {     return _timesheet.where(w => w.username == username).tolist(); } 

this should it:

var usernamesbyapprover = approvals     .where(a => a.approver == "warheat1990")     .selectmany(a => a.details.select(d => d.username)); var timesheetsbyapprover = timesheets     .where(t => usernamesbyapprover.contains(t.username)); 

note if query split 2 expressions, entity framework convert single sql query once evaluate timesheetsbyapprover variable because of deferred execution.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -