Click here to Skip to main content
15,905,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to run some Entity Framework 6 executions under a different collation.

( I have not chance to modify my DB collation )

For example if the user is searching for a text containing the word "maría" (note the accent) EF should return

Maria
maria
maría
....

Using EF should you should do something like this:

var persons = context.Set<Person>().Where( p => p.firstName.Contains("maría") );	


In transact sql there is an option
 selec * from Persons where firstName like '%maría%' 
collate Latin1_General_CI_AI; 


I need to do something similar to force EF to run under other collation.

Thanks all !!!

What I have tried:

I've haven't tryed anithing yet :-)
Posted
Updated 3-Mar-17 12:21pm
v2

1 solution

Entity Framework doesn't have any collation. It's entirely dependent on the database doing that kind of work.

You can either execute a SQL statement you write, including the COLLATE clause, using EF and EF will happily hydrate the data into objects, or you do a database migration and alter the collation for the columns you want.
C#
string query = "SELECT ....";
var result = contextInstance.Database.SqlQuery<targetEntityType>(query);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900