Select multiple records based on list of Id’s with linq

You can use Contains() for that. It will feel a little backwards when you’re really trying to produce an IN clause, but this should do it:

var userProfiles = _dataContext.UserProfile
                               .Where(t => idList.Contains(t.Id));

I’m also assuming that each UserProfile record is going to have an int Id field. If that’s not the case you’ll have to adjust accordingly.

https://stackoverflow.com/questions/16824510/select-multiple-records-based-on-list-of-ids-with-linq

,

Leave a Reply

Your email address will not be published. Required fields are marked *