Possible Duplicate:
What are the benefits of Persistence Ignorance?
After some time and some questions trying to figure out the entity framework, I've come to the conclusion that I just don't get what the point of persistence ignorant objects is.
As best as I can tell, the practical difference between using persistence-aware objects and persistance-ignorant ones is that one gets used something like
Person p = Person.Load(id);
p.Active = false;
p.Save();
and the other is used along the lines of
using (var context = new MyContext())
{
Person p = context.Persons.Single(x => x.ID == id);
p.Active = false;
context.SaveChanges();
}
In the first case, I can return p
, and call Save()
at some later point. In the latter, I could return p
, but I'd need to put it into a new MyContext()
to save it. In the first case, assuming that Person inherits Load() and Save() from some base object which actually handles the database logic, if I wanted to change the persistence, it would just involve changing that base object (or even just have an IPersistent
interface which multiple base classes can implement to access multiple stores). In the latter, I would need to change every instance of MyContext
if the persistence layer changed, and it would be hideously complicated to do piecemeal.
My impression is that persistence-ignorance is a good thing. I just can't understand why. It seems like it's much more complicated to set up, work with, change wholesale and change piecemeal, with no advantage for that complication. Am I just missing something important, or is my entire understanding of what persistence-aware/ignorant means flawed?