My problem is the following:
I’m looking for a solution in LINQ which translates a LINQ expression to SQL LIKE query.
(I know in LINQ I can use Contains, StarsWidth, EndWidth instead of ‘LIKE’ but in my case is not a good solution, and if you check the generated sql script you will see it is not use LIKE)
I found a lot of article that use the System.Data.Linq.SqlClient.SqlMethods.Like methods
so I wrote my query:
var query = from c in _context.prgCity where SqlMethods.Like( c.FullName, "%buda") select c.FullName + "|" + c.prgCountry.CountryName;
return query.ToList<string>();
But when query is running I get the following error message:
“LINQ to Entities does not recognize the method ‘Boolean Like(System.String, System.String)’ method, and this method cannot be translated into a store expression.”
Anybody can Help me what I do wrong?
You’re trying to use
SqlMethods.Likewhen from LINQ to Entities. As per the documentation:You haven’t really explained why
Contains/StartsWith/EndsWithdon’t work for you (and in my experience they do get translated intoLIKEclauses).