Databinding to an Entity Framework in WPF

Posted by King Chan on Programmers See other posts from Programmers or by King Chan
Published on 2012-02-17T20:34:23Z Indexed on 2012/12/01 5:19 UTC
Read the original article Hit count: 434

Filed under:
|
|

Is it good to use databinding to Entity Framework's Entity in WPF?

I created a singleton entity framework context:

  1. To have only one connection and it won't open and close all the time.
  2. So I can pass the Entity around to any class, and can modify the Entity and make changes to the database.

All ViewModels getting the entity out from the same Context and databinding to the View saves me time from mapping new object, but now I imagine there is problem in not using the newest Context:

A ViewModel databinding to a Entity, then someone else updated the data. The ViewModel will still display the old data, because the Context is never being dispose to refresh.

I always create new Context and then dispose of it. If I want to pass the Entity around, then there will be conflicts between Context and Entity.

What is the suggested way of doing this ?

© Programmers or respective owner

Related posts about design

Related posts about wpf