简体   繁体   English

实体框架将参数作为Unicode发送会导致性能问题

[英]Entity Framework sending parameters as unicode causing performance problems

We have built a EF1 model over a legacy SQL Database. 我们已经在旧版SQL数据库上建立了EF1模型。

In this database there are columns with non-unicode strings. 在此数据库中,存在带有非Unicode字符串的列。 These columns are also used as keys. 这些列也用作键。

We had a problem with performance with one specific query. 一个特定查询的性能出现问题。 We noticed that EF was sending the parameter as Unicode. 我们注意到EF将参数作为Unicode发送。

We then rewrote this part of the code to run a SQL statement directly, and send the parameter as a non-unicode string. 然后,我们重写了这部分代码以直接运行SQL语句,并将参数作为非Unicode字符串发送。

The difference was as follows: 区别如下:

  • With EF : 23000 ms 使用EF: 23000毫秒
  • Without EF: 90 ms 不使用EF: 90毫秒

What appears to be happening is that SQL server takes the field from each of the 50000 rows converts it to Unicode to compare it with the parameter being sent in. 似乎正在发生的情况是,SQL Server从50000行的每一行中获取该字段,并将其转换为Unicode,以将其与发送的参数进行比较。

Anyone know how to get EF to send the parameter as a non-unicode string? 有人知道如何获取EF以非Unicode字符串形式发送参数吗? Or any other way to fix this. 或任何其他方法来解决此问题。

That [and many other issues impacting performance] is fixed in EFv4. EFv4中已解决此问题(以及许多其他影响性能的问题)。 Your best bet is to use EFv4 (Entity Framework in .net 4.0) instead of EFv1 (Entity Framework in .net 3.5). 最好的选择是使用EFv4(.net 4.0中的实体框架),而不是EFv1(.net 3.5中的实体框架)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM