Assuming the situation looks like this: My app has an object context and I download 15k records from DB ( Like 15k invoices) The user chooses one and makes some changes in it. I call SaveChanges () and it fails for some reason (no reason).
Any reference that was used now can not be saved because it was not able to save those changes. What should I do to do this work?
Another scenario is that if I use a different reference to make changes, if savings fail then nothing happens - I abandon the context and this is the same. The problem arises: How to merge changes back into the main context? (15k records without downloading again)
The idea of downloading 15k records is a very bad smell , But you think you should. To create this work, you should see the scenario you should follow:
- Create the first reference for data retrieval.
- Execute the query to get your 15k record. Execute the query as
NoTracking (
MergeOption of
ObjectQuery )! This will improve performance because these records will never be used in context.
- Close the first reference
- Selects the user and create a deep clone of the invoice = invoice and attach it in a new context (in the case of WPF or WinForm application)
- User saves changes and exceptions are removed. If you want to deal with an exception, you still have only one reference with a single invoice. You can settle the issue and return to your original set of unaffected records.
- If the entity has been saved, you should be added back to the list because your institution will not be automatically updated in 15k records.
Comments
Post a Comment