c# - How do I combine these two linq queries into a single query? -


how can in 1 query? want person company matches name of person i'm searching for.

currently company , run same search.

var existingcompany = bidinfo.companies         .firstordefault( c=> c.companydomain != null &&                             c.companydomain.people.firstordefault(                                   p => p.name == bidinfo.architectperson.name )                                          != null); person existingperson=null; if (existingcompany !=null) {      existingperson = existingcompany.companydomain.people.firstordefault(p => p.name == bidinfo.architectperson.name); } 

assuming understand you're trying do, this:

var person = bidinfo.companies             .where(c=>c.companydomain != null)             .selectmany(c=>c.companydomain.people)             .singleordefault(p=>p.name == bidinfo.architectperson.name); 

note you're not filtering on company (you're getting first company has name, if there multiples? if that's not possible company check useless , may do , select people filter on instead of going inside of each company, checking if person there, somehow going , down!)


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -