关于我如何教程的问题(WPF / Entity Framework / ObservableCollections)

时间:2010-09-04 04:45:34

标签: c# wpf linq entity-framework

我看了How Do I: Build a WPF Data Entry Form Using Entity Framework?

15:30左右很困惑。当主持人说出像

这样的话
  

当您创建LINQ查询时,我们不会获得丰富的集合......

她的意思是我的“富人”。

起始代码看起来......这有什么不对。即使我使用LINQ查询更改db.Customers.Execute(...),代码仍然有效。为什么需要一个新的可观察集合以及为什么ListCollectionView而不是BindingListCollection视图。什么是2

之间的差异
// customerSource is a CollectionViewSource stored in Window.Resources
// db is of type OMSEntities (which is the Entity Collection Name, what does this mean?)
customerSource.Source = db.Customers.Execute(...);
this.view = (BindingListCollectionView) customerSource.View;

看起来之后的代码(~21:38)

results = from cust in db.Customers ...
customerData = new CustomerCollection(results, db);
customerSource.Source = customerData
view = (ListCollectionView) customerSource.View;

1 个答案:

答案 0 :(得分:3)

她意味着你将获得一个IEnumerable,它不支持双向绑定或额外的设施,如添加/删除事件的通知,这些设备在其他集合类型中可用。因此,代码采用IEnumerable并将结果放入具有这些功能的“更丰富”的集合类型中。