问题描述
我想将 ids 数组中的值与 ItemsOfCars 表中的 ItemID 值进行比较。 ItemsOfCars 是多对多的表关系。
例如,我在 ItemsOfCars 中有值 1,2,3,4,5。 我在名为 ids 的数组中有值 1、2。 我想比较它们并获取 ItemsOfCars 数组中但不在 ids 数组中的值 3、4、5。
[HttpPost]
public IActionResult GetItems(int[] ids)
{
foreach (var item in items)
{
item.ItemsOfCars.Where(x => x.ItemId == ids)
}
}
解决方法
试试这个:
public IActionResult GetItems(int[] ids)
{
var items= ItemsOfCars.Where(i => !ids.Contains(i.ItemId));
}