1

In the code below, profile is a string. I would like to know how to write a query in case where profile is a string array or list. ie the array or list can have multiple elements like { 'Profile1','profile2'}

var ccData = (from p in db.ChannelContacts where p.ProfileId == profile select p);

2 Answers 2

2

You could use an efficient join:

var ccData = from p in db.ChannelContacts 
             join profileID in profiles // your collection
             on p.ProfileId equals profileID
             select p;

another less efficient option is Contains:

var ccData = from p in db.ChannelContacts 
             where profiles.Contains(p.ProfileId)
             select p;
Sign up to request clarification or add additional context in comments.

Comments

1

Simply ask, if profile contains that ProfileId

var ccData = (from p in db.ChannelContacts 
              where profile.Any(prof => prof == p.ProfileId) 
              select p);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.