Question : LINQ - Contains for IN statement not working?

I saw many posts that could use a .Contains on an arraylist or string array etc.  Everytime I am now getting:

LINQ to Entities does not recognize the method 'Boolean Contains(System.Object)' method, and this method cannot be translated into a store expression.

Any idea what else I can use to get the IN statement to work?

    var res = from c in CUSTOMER
                          where
                          custarray.Contains(c.CUST_ID)
                          select new Funds
                          {
                              CustId = c.CUST_ID
                          };

Answer : LINQ - Contains for IN statement not working?

If I understand your question correctly you can simply cross join your LINQ expression.

I've quickly worked out a sample for you, but I'm very sorry... I'm a VB.NET guy. So bear with me for a sec.

See code attached.

Hope I helped.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
Imports System.Text 
Public Class Form1 

    Private _custs As CustomerList
    Public Property Custs() As CustomerList
        Get
            Return _custs
        End Get
        Set(ByVal value As CustomerList)
            _custs = value
        End Set
    End Property 

    Private Sub Command1_Click() Handles Button1.Click
        Dim res = From c In Custs _
                  From f In c.Funds _
                  Where c.Name = "Shell" _
                  Select f 
        Dim s As New StringBuilder
        For Each item In res
            s.AppendLine(item.ID.ToString)
        Next
        MessageBox.Show(s.ToString)
    End Sub 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Custs = New CustomerList
        custs.Add(New Customer With {.Name = "Shell"})
        custs(0).Funds = New FundList
        custs(0).Funds.Add(New Fund With {.ID = 1})
        custs(0).Funds.Add(New Fund With {.ID = 2})
        custs(0).Funds.Add(New Fund With {.ID = 3})
        custs.Add(New Customer With {.Name = "Toyota"})
        Custs(1).Funds = New FundList
        Custs(1).Funds.Add(New Fund With {.ID = 4})
        Custs(1).Funds.Add(New Fund With {.ID = 5})
    End Sub
End Class 
Public Class Customer 

    Private _name As String
    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property 
    Private _funds As FundList
    Public Property Funds() As FundList
        Get
            Return _funds
        End Get
        Set(ByVal value As FundList)
            _funds = value
        End Set
    End Property 
End Class 
Public Class CustomerList
    Inherits List(Of Customer) 
End Class 
Public Class Fund 
    Private _id As Integer
    Public Property ID() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property 
End Class 
Public Class FundList
    Inherits List(Of Fund) 
End Class
Random Solutions  
 
programming4us programming4us