Linq to SQL how to do “where [column] in (list of values)”

前端 未结 5 1707
情话喂你
情话喂你 2020-11-29 20:43

I have a function where I get a list of ids, and I need to return the a list matching a description that is associated with the id. E.g.:

public class CodeDa         


        
5条回答
  •  甜味超标
    2020-11-29 21:37

    Use

    where list.Contains(item.Property)
    

    Or in your case:

    var foo = from codeData in channel.AsQueryable()
              where codeIDs.Contains(codeData.CodeId)
              select codeData;
    

    But you might as well do that in dot notation:

    var foo = channel.AsQueryable()
                     .Where(codeData => codeIDs.Contains(codeData.CodeId));
    

提交回复
热议问题