Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Persistence Ignorance

People are talking about Microsoft's Entity framework and how it does not currently allow persistence ignorant domain objects.

I've been torn about this issue for a while now. On the one hand, having an O/R mapper that is persistent ignorant essentially means that it has to support XML mapping files. The downside to this approach is duplication of each entity's properties (which leads to managing them in multiple places), having to edit and maintain these files, and not being able to see mapping information all in one place. This price is often worth it, though.

On the other hand, using attributes to specify mapping information leads to less "code" to manage, and the advantage of having your domain class and mapping information all in one location. The price is that your domain objects have to know about the persistence framework.

The one thing I've observed recently is that most of the Java developers I've talked to who've used Hibernate in the past are excited and relieved that the latest versions support annotations (attributes in .NET) for specifying mapping information. Most of them seem to dislike mapping via XML files, and feel that the price of using annotations is worth it.

It's too bad for Microsoft that nHibernate already supports both methods, so they'll have to as well if they want to keep up.


Posted 03-14-2007 7:53 PM by Jeff Perrin
Filed under: , ,

[Advertisement]

Comments

Christopher Bennage wrote re: Persistence Ignorance
on 03-15-2007 8:15 AM

I definitely find myself leaning toward attributes right now.  I agree with you about the duplication of properties.

However, (and I will confess the influence of <a href="http://en.wikipedia.org/wiki/Ruby_on_Rails#Philosophy">Ruby's convention over configuration</a>) I am considering the value of mapping based on naming conventions (supplemented by attributes for unusual conditions, or maybe even [sigh] a config file).  

What are your thoughts on that?

Christopher Bennage wrote re: Persistence Ignorance
on 03-15-2007 9:39 AM

I just thought of one objection. Mapping based on naming convention would make the database and the domain model too tightly coupled.

BTW, sorry for the html in the last post.  I forgot it's not supported.

Jeff Perrin wrote re: Persistence Ignorance
on 03-15-2007 5:18 PM

I personally enjoy attributes over XML, and am willing to give up persistence ignorance for them as well. As far as Ruby is concerned, the Rails folks have a huge advantage in that they *don't* map by convention... The database columns *are* the domain entity's properties. There is no mapping at all, it's just done automagically on the fly with method_missing and some dynamic code generation. Rails is 100% DRY when it comes to ActiveRecord.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)