I'm using code first and have a number of entities that have a requirement to have a "work in progress" version of each. Traditionally we've implemented this pattern by cloning the tables for all of these entities with a prefixed "wip." version. Although this system works there is a lot of uglyness in the code and I'm hoping to find a cleaner less obtrusive solution using Entity Framework.
Ideally I'd love something close to this:
using (MyDBContext ctx = new MyDBContext()) {
Person myPerson = ctx.First(x => x.Name == "frank");
// Do work with the non "work in progress" entities
}
using (MyWIPContext wipCtx = new MyWIPContext()) {
Person myPerson = wipCtx.First(x => x.Name == "frank");
// Do work with the "work in progress" entites
// If I need to move this entity to non "Work in Progress" maybe do:
ctx.Attach(myPerson);
ctx.SaveChanges(); // Where ctx is the non "Work in Progress context"
}
From my digging I feel like this might be possible. I found that I can add a rule to prefix "wip." in front of my tables (How to Add Table Prefix In Entity Framework Code First Globally?)
Also found a post deal with multiple schema's (Entity Framework and multiple schemas) Referencing this article (http://romiller.com/2011/05/23/ef-4-1-multi-tenant-with-code-first/)
Some of the problems I'm hitting is with using migrations to create the database. If I have multiple DBContext's migrations start getting messy and with that second article they don't work at all as they don't give there DBContext a way to be constructed so migrations fail.
Does anyone know of a clean way to implement this pattern. I'd love to have it as non obtrusive as possible. The entities should not be aware that they have 2 places they can persist in (Work in Progress & Real Version). I know I could do this by adding flags to the entities but I feel like there is another way.