asp.net mvc - LINQ to SQL - Filtering the dataset between two nested collections -


i have mvc 3 project in visual studio c#. have linq sql query works fine , following example listed elsewhere on stackoverflow:

comparing 2 lists using linq sql

i have been able reduce results 2 nested collections match. bit of code did trick (example link above):

var anydesiredskills = canidateskills.any( c => desiredskills.select( ds => ds.skillid ).contains( c.skillid ) ); 

i've adapted successfully, need able filter records using more 1 condition. wondering if able adapt above show how include more 1 condition?

to give background on goal is:

  1. a search page can select number of contacts
  2. each contact added search criteria may/may not have 'role' assigned. if role present should factored in query.
  3. results returned based on dynamic criteria.

thanks in advance , :o)

it sounds you're looking like:

var desiredskillids = desiredskills.select(_=>_.skillid).tolist(); var matchingcontacts =   contact in contacts   contact.role == null || desiredroles.contains(contact.role)   contact.skills.any(cs=> desiredskillids.contains(cs.skillid))   select contact; 

or in method-based syntax:

var matchingcontacts = contacts   .where(contact => contact.role == null || desiredroles.contains(contactrole))   .where(contact => contact.skills.any(cs => desiredskillids.contains(cs.skillid))); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -