The only place I've found that uses a collation is Entity SQL's ORDER BY clause.
You could use SqlQuery as shown here to use a SQL string (with parameters of course) that uses the COLLATE clause :
var query = "select Name from Customers " +
" where Name COLLATE Turkish_CI_AI like @name";
var results = myContext.Customers
.SqlQuery(query,new SqlParameter("@name","%ozgur%"))
.ToList();
I'd advise caution though. LIKE '%...%'
can't benefit from any indexes that cover the name
field and will have to search the entire table. Even Name = @name COLLATE ...
may not use any indexes the collation doesn't match the collation the index was built with.
You should consider using full text search indexes and make full text search queries for specific words, eg:
SELECT Name from Customers WHERE CONTAINS(Name ,@thatName)
Update
Another option is to use an interceptor to change the SQL generated by a clause, as shown in this SO question. That interceptor uses a regular expression to replace LIKE
with CONTAINS
. A simpler expression could be used to inject the COLLATE
clause before LIKE
The code isn't trivial, but at least it's an option.