I've only been looking at the EF a week but the more I delve the more I find that there's either something fundamental missing, or that its been developed by 10 developers in different rooms... in different buildings.
I'm looking at optimisticconcurrency and can see at least 2 different ways of foing the same thing, but which ones is right in my case? I'm using EF 4.1, with an edmx from the database and DbContext rather than ObjectContext.
I've found 2 exceptions that fit the bill, the first is OptimisticConcurrencyException and the second
DbUpdateConcurrencyException.Here's the reload statement:
ex.Entries.Single().Reload();
If there are multiple exceptions is this going to fail again - I'm not sure, anyone help?
The Reload support for an instance of Entity not multiple. There's no refresh or Reload the whole data from database. Except you convert DbContext back to ObjectContext because DbContext base on ObjectContext.
sephiroth100
Participant
1118 Points
1001 Posts
Optimistic conncurrency exceptions
Feb 20, 2012 07:02 PM|LINK
I've only been looking at the EF a week but the more I delve the more I find that there's either something fundamental missing, or that its been developed by 10 developers in different rooms... in different buildings.
I'm looking at optimisticconcurrency and can see at least 2 different ways of foing the same thing, but which ones is right in my case? I'm using EF 4.1, with an edmx from the database and DbContext rather than ObjectContext.
I've found 2 exceptions that fit the bill, the first is OptimisticConcurrencyException and the second DbUpdateConcurrencyException.Here's the reload statement:
ex.Entries.Single().Reload();
If there are multiple exceptions is this going to fail again - I'm not sure, anyone help?
Thanks
John
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Optimistic conncurrency exceptions
Feb 22, 2012 01:21 AM|LINK
Would you mind showing us your codes and point out where the error is thrown out?
Reguards!
thaicarrot
Contributor
5132 Points
1465 Posts
Re: Optimistic conncurrency exceptions
Feb 22, 2012 08:12 AM|LINK
The Reload support for an instance of Entity not multiple. There's no refresh or Reload the whole data from database. Except you convert DbContext back to ObjectContext because DbContext base on ObjectContext.
How to solve.
Convert DbContext to ObjectContex
private ObjectContext objectContext;
private void RefreshExecute()
{
objectContext = ((IObjectContextAdapter)context).ObjectContext;
objectContext.Refresh(RefreshMode.StoreWins, this.context.Entities);
}
EF 4.1+ has been changing overtime so that is it still not consistency at the moment
EF 5 is best.
Weera