强制EF在不同的排序规则下运行 [英] Force EF to run under different collation

查看:86
本文介绍了强制EF在不同的排序规则下运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要在不同的排序规则下运行一些Entity Framework 6执行。



(我没有机会修改我的数据库整理)



例如,如果用户正在搜索包含单词maría的文本(请注意重音)EF应该返还



Maria

玛丽亚
$ b $bmaría

....



使用EF你应该这样做:



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





在transact sql中有一个选项

 selec *来自第一名的人比如'%maría%'
整理Latin1_General_CI_AI;





我需要做类似的事情,迫使EF在其他整理下运行。



全部谢谢!



我尝试过:



我还没有尝试过anithing: - )

解决方案

实体框架没有任何整理。它完全依赖于数据库做这种工作。



您可以执行您编写的SQL语句,包括COLLATE子句,使用EF和EF将愉快地保持水合作用将数据转换为对象,或者进行数据库迁移并更改所需列的排序规则。

  string  query =   SELECT ....; 
var result = contextInstance .Database.SqlQuery< targetEntityType > (查询);


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 :-)

解决方案

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.

string query = "SELECT ....";
var result = contextInstance.Database.SqlQuery<targetEntityType>(query);


这篇关于强制EF在不同的排序规则下运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆