Linq SqlMethods.Like fails

Posted by Russell Steen on Stack Overflow See other posts from Stack Overflow or by Russell Steen
Published on 2010-04-06T12:02:21Z Indexed on 2010/04/06 12:03 UTC
Read the original article Hit count: 336

Filed under:
|

I'm following the tips here, trying to leverage the statement that the sql doesn't get created until the enumerator is tripped. However I get the following error on the code below. I'm using Linq2Entities, not linq2sql. Is there a way to do this in Linq2entities?

Method 'Boolean Like(System.String, System.String)' cannot be used on the client; it is only for translation to SQL.

            query = db.MyTables.Where(x => astringvar.Contains(x.Field1));

            if (!String.IsNullOrEmpty(typeFilter))
            {
                if (typeFilter.Contains('*'))
                {
                    typeFilter = typeFilter.Replace('*', '%');
                    query = query.Where(x=> SqlMethods.Like(x.Type, typeFilter));
                }
                else
                {
                    query  = query.Where(x => x.Type == typeFilter);
                }
            }

© Stack Overflow or respective owner

Related posts about .NET

Related posts about linq-to-entities