简体   繁体   中英

Linq - How to select items from a list that contains only items of another list?

I have this two classes:

public class Item
{
   public int Id{get;set;}
   public List<Test> TestList{get;set;} 
}
public class Test
{ 
   public int Id{get;set;}
   public Item Item{get;set;}
   public byte State{get;set;}
}

这将返回所有状态都在stateList ,我认为这就是您所需要的:

Items.Where(x => x.TestList.All(s => stateList.Contains(s.State)));

如果您只需要TestList只有状态为2的项目的项目:

tems.Where( i => i.TestList.All(li => li.State == 2))

I have similar issue:

List<string> mds = _userService.GetAllMDUsers();
conf = _context.BillingsConfirmationsView.Where(c=> mds.Contains(c.EmployeeShort.ToUpper()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM