微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Linq Where inside a where

如何解决Linq Where inside a where

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

解决方法

试试这个:

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。