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);
}
}
Notes: db is a entity mapping to a sql server.
See Question&Answers more detail:os