WPF是否会破坏实体框架ObjectContext? [英] Does WPF break an Entity Framework ObjectContext?

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

问题描述

我开始使用Entity Framework 4,并且准备编写WPF演示应用程序以更好地学习EF4.我的LINQ查询返回IQueryable<T>,我知道可以使用以下代码将它们放入ObservableCollection<T>中:

I am getting started with Entity Framework 4, and I am getting ready to write a WPF demo app to learn EF4 better. My LINQ queries return IQueryable<T>, and I know I can drop those into an ObservableCollection<T> with the following code:

IQueryable<Foo> fooList = from f in Foo orderby f.Title select f;
var observableFooList = new ObservableCollection<Foo>(fooList);

到那时,我可以在视图模型上将适当的属性设置为可观察的集合,然后我将在视图和视图模型属性之间获得WPF数据绑定.

At that point, I can set the appropriate property on my view model to the observable collection, and I will get WPF data binding between the view and the view model property.

这是我的问题:将foo列表移至可观察的集合时,是否会中断ObjectContext?或者换种说法,假设我以其他方式正确处理了ObjectContext,EF4是否会正确更新模型(和数据库)?

Here is my question: Do I break the ObjectContext when I move my foo list to the observable collection? Or put another way, assuming I am otherwise handling my ObjectContext properly, will EF4 properly update the model (and the database)?

我问的原因是:NHibernate在集合级别跟踪对象.如果将NHibernate IList<T>移至可观察的集合,则会破坏NHibernate的更改跟踪机制.这意味着我必须做一些非常复杂的对象包装才能使NHibernate与WPF一起使用.我正在将EF4看作是省掉所有这些的一种方式.

The reason why I ask is this: NHibernate tracks objects at the collection level. If I move an NHibernate IList<T> to an observable collection, it breaks NHibernate's change tracking mechanism. That means I have to do some very complicated object wrapping to get NHibernate to work with WPF. I am looking at EF4 as a way to dispense with all that.

因此,要使EF4与WPF一起使用,是否就像将我的IQueryable<T>结果放入ObservableCollection<T>一样简单?这样可以保留我的EDM实体对象上的更改跟踪吗?感谢您的帮助.

So, to get EF4 working with WPF, is it as simple as dropping my IQueryable<T> results into an ObservableCollection<T>. Does that preserve change-tracking on my EDM entity objects? Thanks for your help.

推荐答案

您需要将ObservableCollection与Ob​​jectContext同步.如何完成的操作显示了 WPF应用程序框架(WAF) 的BookLibrary示例. .寻找EntityObservableCollection.

You need to sync the ObservableCollection with the ObjectContext. How this can be done shows the BookLibrary sample of the WPF Application Framework (WAF). Look for the EntityObservableCollection.

这篇关于WPF是否会破坏实体框架ObjectContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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