I am new to EntityFramework.
In my application, reference item is a pool of examples (each reference has 1 connection to DB.)
The problem is that when I call an object (and save the change) ), The data is updated in DB and in the updated context, but when I select from any other example, this is the old data of the selected object.
Example:
Let's imagine a table named TBL.
The table has 2 columns: ID and data
1 row: ID = 1, data = 2.
EFContext References 1 = New EFCTX (); EFContext References 2 = New EFContext (); Var obj1 = context1.tbl.Where (a => a.id == 1); Var obj2 = context2.tbl.Where (a => a.id == 1); Obj2.data = 10; Context2.SaveChanges (); Var obj3 = context1.tbl.Where (a => a.id == 1); After executing these lines, obj3.data has 2 instead of 10.
How can I solve this problem?
Every time I want to reach DB, I want to create a reference instance.
Refresh I do not have to do before every query (my application is multilingual), and takes a lot of it.
If I try to choose once every time I I am doing so, there was a way to tell the outline of an entity, it would be great.
Thank you!
You have to reconsider your design. References are very light and generally standard practice is to create a per-transaction or work unit. When dealing with database interaction, I have a good rule of thumb as open as long as possible and close them as soon as possible, in your case you can unnecessarily open except for changed database connections.
You should consider implementing a better design pattern for your problem, take a look at
Comments
Post a Comment