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; }
    }

Using these example objects,

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

I tried linq query below but I am getting an error

Query I am trying:

    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();

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

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

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

David Edel
  • 569
  • 4
  • 18
  • Does this answer your question? [Using Linq to Sql asynchronously with new async/await](https://stackoverflow.com/questions/12498564/using-linq-to-sql-asynchronously-with-new-async-await) – Jawad Dec 31 '19 at 21:22
  • No, my question is not about async await, it is about the matching 2 properties using the .any on my list – David Edel Dec 31 '19 at 21:26

2 Answers2

1

Try this:

var localIdPairs = listOfOrderItems.Select(x => x.OrderId + "-" + x.ProductionItemId).ToList();

var results = await db.InventoryItems
          .Where(d => !d.DeleteFlag && 
                      localIdPairs.Contains(d.OrderId + "-" + d.ProductionItemId))
          .Select(t => t.InventoryItemID).ToListAsync();
Hadi Samadzad
  • 1,480
  • 2
  • 13
  • 22
1

Looking further into the error I found this error:

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

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

David Edel
  • 569
  • 4
  • 18