views:

1295

answers:

3

"Method 'Boolean Contains(System.String)' has no supported translation to SQL."

query is IsQueryable but this stopped working:

foreach (string s in collection1)
{
       if (s.Length > 0)
                {
                    query = query.Where(m => m.collection2.Contains(s));

                }
}

UPDATE: it works when i make query "ienumerable" instead of iqueryable. What would be the way to get same result using linq instead of iterating through loop?

A: 

It looks like the error you are seeing is coming from the collection collection 2. Have you tried wrappering the m.collection2 in another function which returns true or false? Is this LINQ syntax?

ewalk
+2  A: 

Take a look at this answer from stackoverflow.

It looks like the resulting query would need access to something that the database has no way of reaching, because the info is in memory.

Klinger
A: 

Since m.collection2 is in the database, don't use Contains. Use Any

m.collection2.Any(x => x == s)
David B