Linq Where inside a where

时间:2020-12-26 13:36:46

标签: c# asp.net-mvc entity-framework linq asp.net-core-mvc

我想将 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)
        }
    }

enter image description here enter image description here enter image description here

1 个答案:

答案 0 :(得分:-1)

试试这个:

public IActionResult GetItems(int[] ids)
    {
   
      var items=  ItemsOfCars.Where(i => !ids.Contains(i.ItemId)); 
    }
相关问题