使用Linq匹配本地列表中任何对象的2属性 [英] Match 2 property of any object in local list using Linq

查看:50
本文介绍了使用Linq匹配本地列表中任何对象的2属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    public class OrderItem
    {
        public int OrderID { get; set; }
        public int ProductionID { get; set; }
    }

    public class InventoryItem
    {
        public int InventoryItemID{ get; set; }
        public int OrderID { get; set; }
        public int ProductionID { get; set; }
        public bool Created { get; set; }
        public bool Deleted { get; set; }
    }

使用这些示例对象,

我有一个本地的orderItems列表,并且想查询其中两个订单项的两个属性上的OrderID和ProductionID都匹配的库存项目

I have a local list of orderItems and want to query inventory items where OrderID and ProductionID matches on both properties any of my list of Order Items

我在下面尝试了linq查询,但出现错误

I tried linq query below but I am getting an error

我正在尝试查询:

    var results = await db.InventoryItems.Where(d =>
                  listOfOrderItems.Any(o => o.OrderID == d.OrderID && !d.DeleteFlag && d.ProductionId == o.ProductionItemId))
                  .Select(t => t.InventoryItemID).ToListAsync();

抛出异常:EntityFramework.SqlServer.dll中的'System.NotSupportedException'

Exception thrown: 'System.NotSupportedException' in EntityFramework.SqlServer.dll

编辑 我被问到以下问题:使用Linq与Sql异步新的异步/等待

EDIT i am being referred to this question:Using Linq to Sql asynchronously with new async/await

但是我的问题不是关于异步等待,而是关于使用列表中的.any匹配2个属性的信息.

But my question is not about async await, it is about the matching 2 properties using the .any on my list

推荐答案

进一步查看错误,我发现此错误:

Looking further into the error I found this error:

在此上下文中仅支持基本类型或枚举类型.

Only primitive types or enumeration types are supported in this context.

我的收藏listOfOrderItems的类型为List,将其更改为IEnumerable解决了我的问题

My collection listOfOrderItems was of type List, changing it to IEnumerable fixed my problem

这篇关于使用Linq匹配本地列表中任何对象的2属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆