阻止EF4设计器生成DefiningQuery [英] Prevent the EF4 designer from generating a DefiningQuery

查看:50
本文介绍了阻止EF4设计器生成DefiningQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以阻止设计师为视图创建一个DefiningQuery?我可能在sql server中没有明显的性能 - 但对于mysql来说,这是另一回事。它将在20秒内运行2秒查询。

Is there any way I can prevent the designer to create a DefiningQuery for views ? I might not make a difference performance wise in sql server - but for mysql it's another matter . It will make a 2 seconds query run in 20 .

 

推荐答案

设计器生成为任何没有主键的对象定义查询,主键是视图或任何没有主键的表。导入视图时,它会自动将所有非空列标记为主键。现在我认为发生的事情可能是b $ b,因为密钥由很多列组成,因此您需要承担身份管理费用。这意味着当您查询视图时,EF会应用标识管理,这会花费更长的时间。不确定这是不是问题。要确认它是
,请尝试使用MergeOption.NoTracking运行查询,如下所示。

Designer generates definingquery for any object that does not have a primary key which is a a view or any table that does not have primary key. When it imports the view, it automatically marks all non null columns as primary key. Now i think what might be happening is you are incurring the identity management cost because the key is comprised of so many columns. This means when you query the view, EF applies identify managment which is taking longer. Not sure if this is the problem. To confirm it try running the query with MergeOption.NoTracking like below.

db.CustomerViews.MergeOption = MergeOption.NoTracking;

db.CustomerViews.MergeOption = MergeOption.NoTracking;

db.CustomerViews.ToList();

db.CustomerViews.ToList();

如果没有mergeoption和mergeoption的查询需要相同的时间,则表示问题出在其他地方。如果它更快,那么您可以转到设计器并修改键以指定视图的真实键。更改概念
模型上的键也将更改ssdl部分的键。因此,当您更新模型时,密钥不会被覆盖。

if the query without mergeoption and with mergeoption takes same time then it means the problem is somewhere else. If its faster then you can go to the designer and modify the keys to specify the real key for the view. Changing the key on the conceptual model will also change the key on the ssdl section as well. So, when you update the model, the key wont be overwritten.


这篇关于阻止EF4设计器生成DefiningQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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