I’ve been wondering for some time if there is any way in Entity Framework to save some changes to the database and others not. Imagine a situation in which I have let’s say 4 entity classes – Customer, Task, SalesSchema and Address. Each of those is a customers one-to-many relationship. Now I create a window with 3 tabs (using TabControl) and each of those has a DataGridView that lists adresses, tasks and sales schemas and also for each of those buttons(add, modify, delete) to handle details of each entity type.
What I want to do is to allow partial change commits to database eg. user adds a task -> it’s supposed to be saved immediately when the user hits save changes, but only changes from active tab are supposed to be saved. (don’t ask me why I have to do this – this is how the client wants it)
It is now achieved by creating separate data contexts and committing each of those separately, but I wonder if there is another way to do this – using one object context.
In ADO.NET datasets there was a way of commiting changes separately – get changes, do some staff that is necessary or even reject the change.
Is this possible with ADO.NET Entity Framework?
I am not sure if I understand your problem correctly / entirely, but most requirements should be handled with one context easily. Below is a simple example of reverting all objects of a certain type to their original state, if you were to call a SaveChanges() on the context after this – only the remaining objects in added or changed state will commit – a partial commit.
The point I’m trying to get across is there is a lot of control available to you if you track the items you’re wanting to “partial” commit. The ones you’re wanting to revert to original state or discard can be reverted or even removed completely from the context.
Not sure if this helps any. Best of luck.