Question : LINQ and NOT IN / Contains Subquery Problem

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:

 
1:
2:
3:
4:
5:
6:
7:
8:
'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) _
                    Select c


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

Answer : LINQ and NOT IN / Contains Subquery Problem

Sorry,

Since cb is already a customerID, I meant:

For each cb in Callbacks
    Customers = From c in Customers Where c.ID <> cb
Next
Random Solutions  
 
programming4us programming4us