本文介绍了当有实体框架时,我们仍然需要bindingsource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实体框架在基础数据源和UI控件之间起着ORM的作用,我想知道我们还需要在EF之上使用bindingsource吗?例如
我可以绑定
datagridview.DataSource = entity.getdata();
而不是
code> bindingsource.DataSource = entity.etdata();
this.datagridview.DataSource = this.bindingsource;
解决方案
显然,您可以直接将Gridview的数据源绑定到实体结果。
但是以下情况如何:
- 将多个控件附加到同一数据源,例如列表+细节
- 通过数据源导航代码隐藏。
可以使用丑陋CurrencyManager完成,但是通过绑定源更好更好的
更多这里
entity framework plays a role as ORM in between the underlying datasource and UI controls, i'm wondering do we still need to use bindingsource on top of EF?
e.g. can i just bind
datagridview.DataSource = entity.getdata();
instead of
bindingsource.DataSource = entity.etdata();
this.datagridview.DataSource = this.bindingsource;
解决方案
Obviously you can directly bind the datasource of the Gridview to the entity result.
But what about following scenarios:
- Having multiple controls attaching to the same datasource, e.g. List+Detail
- Navigating in code-behind through the datasource.
Can be done using "ugly" CurrencyManager but is much nicer through the bindingsource
More here bindingsource "Remarks" section in MSDN
这篇关于当有实体框架时,我们仍然需要bindingsource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!