2010-09-04 33 views
2

我看了How Do I: Build a WPF Data Entry Form Using Entity Framework?有關問題我如何教程(WPF /實體框架/ ObservableCollections)

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; 

回答

3

她意味着你會得到一個IEnumerable,它不具有任何支持雙向綁定或其他設施,如添加/刪除事件的通知,這些設置可用於其他集合類型。因此,代碼採用IEnumerable並將結果放入具有這些特性的「更豐富」的集合類型中。

+0

但我發現如果我用'customerSource.Source ='替換'customerSource.Source = db.Customers.Execute(...)'從cust中的db.Customers中選擇cust'仍然可以正常工作。爲什麼她使用ListCollectionView而不是BindingListCollectionView?我錯過了什麼?對不起,我堅持BindingListCollectionView什麼的,我只是不明白交換機的原因 – 2010-09-04 06:24:54

+1

您是否嘗試添加或刪除行並保存?如果直接綁定到LINQ查詢,那麼來自UI的更新不會被保存。 – 2010-09-04 06:26:50