Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

"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?

like image 376
zsharp Avatar asked Mar 09 '09 05:03

zsharp


1 Answers

Try this:

query = query.Where(m => m.collection2.ToList().Contains(s));
                                       ^^^^^^^^
like image 62
Sunrise Avatar answered Oct 07 '22 20:10

Sunrise