开发者

How to implement INotifyPropertyChanged with LINQ-To-Entity objects

I am using a LINQ-to-Entity Model attached to my database. I can do normal binding using LINQ with no problems, example:

Dim db As New myEntityModel
dim myCustomers As New Customers

myCustomers=db.Customers.ToList

dim myItemSource = From c in myCustomers
                   Select c   

myComboBox.ItemsSource = myItemSo开发者_JS百科urce

Easy! But my question is how do I implement INotifyPropertyChanged so that controls that I bind to are automatically updated whenever the data source changes?


Your code doesn't make a whole lot of sense :-)

First:

dim myItemSource = From c in myCustomers
                   Select c   

This is not needed ad all, you can change the last line to this: myComboBox.ItemsSource = myCustomers. No need for myItemSource. This can be further simplified to myComboBox.ItemsSource = db.Customers.ToList. No need for myCustomers either.

Second:
You want your combobox to be updated when the customers change. Then why are you not binding directly to db.Customers but to a static list that will never change? db.Customers.ToList will create a snapshot of the contents of db.Customers. It will not be updated, when db.Customers is updated.

Conclusion: Your code should look like this:

Dim db As New myEntityModel
myComboBox.ItemsSource = db.Customers
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜