绑定到实体框架 [英] Binding to Entity Framework

查看:148
本文介绍了绑定到实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

msdn文档中,建议不要绑定控件直接对象查询:


我们建议您不要将控件直接绑定到ObjectQuery。
相反,将控件绑定到Execute方法的结果。


我也读了一些答案这里的SO推荐它,也不要绑定到模型本身的实例。然而,我找不到为什么不推荐,因为我迄今为止所做的所有测试似乎工作正常。有没有人可以说明为什么我不应该使用这些对象作为我的绑定的原因?

解决方案

有关为什么我不能将控件绑定到ObjectQuery的问题:



引用从这里


为了确保数据源是最新的,您可能需要使用Execute方法再次执行
的查询。这将将控件
绑定到一个新的ObjectResult。


如果不调用执行,与执行后查询实际返回的内容相比,UI中显示的内容可能不是最新的。当数据库发生更改时,绑定当然不会自动更新。



第二点:


我们建议您不要将控件直接绑定到ObjectQuery。
将控件绑定到Execute方法的结果。在
中绑定此方式可防止在
绑定期间多次执行查询。



In the msdn documentation there is a recommendation to not bind controls directly to an object query:

We recommend that you not bind controls directly to an ObjectQuery. Instead, bind controls to the result of the Execute method.

I've also read some answers here on SO that recommend it and also not to bind to instance of the model itself. Nevertheless I couldn't find why it is not recommended since all of the tests I have done so far seem to work fine.

Could anyone shed some light on the reasons why I shouldn't use these objects for my bindings?

解决方案

For the question "why shouldn't I bind controls to the ObjectQuery":

Quoted from here:

To ensure that the data source is up to date, you may need to execute the query again using the Execute method. This will bind the control to a new ObjectResult.

If you do not call Execute, what's displayed in your UI might be not up-to-date compared to what the query actually returns after being executed. The binding is, of course, not automatically updated when a change occurs in the database.

Second point:

We recommend that you not bind controls directly to an ObjectQuery. Instead, bind controls to the result of the Execute method. Binding in this manner prevents a query from being executed multiple times during binding.

这篇关于绑定到实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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