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

前端 未结 4 924
再見小時候
再見小時候 2020-11-30 18:31

I have a list containing Id\'s of my UserProfile table. How can i select all UserProfiles based on the list of Id\'s i got in a var us

4条回答
  •  佛祖请我去吃肉
    2020-11-30 18:51

    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.

提交回复
热议问题