Entity Framework (3.5) - Reject Changes

c# entity-framework

Question

I have this service which is Singleton and Single threaded and serves bunch of low volume clients. It uses Entity Framework and Data in SQL Server.

If any one of the client's request to Save Data fails, all the subsequent requests are being failed as every time it is trying to save the original failed data object.

Is there is any way to Undo changes to EF data when save fails?

Thanks in Advance

2
11
8/18/2010 6:47:19 PM

Accepted Answer

The Answer to the Question is "You Cannot discard Changes to the Context" instead one has to discard ObjectContext as Marc explained.

4
8/24/2010 7:26:25 PM

Expert Answer

Entity-models / data-contexts / etc are best handled as units of work. If you need to cancel it, simply discard the context and start with a new one. And if you succeed, discard it anyway! Each request should really be using separate data-contexts, otherwise you can get a range of problems:

  • threading (although it sounds you've avoided this by making it single-threaded)
  • data growth (there is an identity manager; every row you touch stays around; multiple times, in fact)
  • general isolation etc
  • connection lifetime management (hogging an open connection)
  • etc
11
8/18/2010 7:03:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow