Reputation: 1977
On my DBMS, I have two tables having one-to-many relationship (A <- B). At the first running, I retrieved some records of A (including B) like this:
var lst = from a in ctx.As.Include("Bs") select a;
So, everything is ok. But a few minutes later, I want to get them again because they could be changed on other apps.
I tried to use
ctx.Refresh(RefreshMode.StoreWins, lst);
When I do that, the only things are refreshed is object from B, not A. Therefore, I must do another step like:
foreach (var a in lst) {
ctx.Refresh(RefreshMode.StoreWins, a.Bs);
}
It's also ok if I didn't include Bs
in the linq statement, then use Load
method instead of Refresh
The problem here is calling Refresh
or Load
too many times maybe decrease the performance. How can I re-load them from the database storage without so many calling?
Thanks!
Upvotes: 0
Views: 87
Reputation: 364259
But a few minutes later ...
Context is unit of work and unit of work usually doesn't take few minutes so the basic answer for your question is create new context and execute the query again.
If you really think that your context must live so long (I doubt that it must because in such case you would not want to overwrite local changes) you can try this:
ctx.As.MergeOption = MergeOption.OverwriteChanges;
ctx.Bs.MergeOption = MergeOption.OverwriteChanges;
var lst = from a in ctx.As.Include("Bs") select a;
Upvotes: 1