I am trying to return a set of data using LINQ and Entity Framework which will only return items where a related item exists and fulfils a set of criteria.
I have the following code:
'Gets a list of customer IDs which have callbacks set
Dim Callbacks = (From f In MyContext.Callbacks.Include("Customer") Where (f.TypeId > 0) Select f.Customer.Id).ToList
'Select customers who DO NOT have callbacks set
Customers = From c In MyContext.Customers _
Where (c.StatusId = 2) _
And Not Callbacks.Contains(c.Id) _
However, I am getting an error:
LINQ to Entities does not recognize the method 'Boolean Contains(Int32)' method, and this method cannot be translated into a store expression.
How can I do this with LINQ? I have tried using one LINQ query (with a nested subquery instead of the Callbacks.Contains(c.Id) ) and two LINQ queries as shown above