BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

ORMs And Persistence Ignorance

| by Roopesh Shenoy on Aug 29, 2013. Estimated reading time: 1 minute |

Julie Lerman recently noted that Entity Framework can work with classes having private constructors and private property setters.

In the test published by Julie, you can see that Entity Framework (EF) is able to populate a property with private setters and invoke a private constructor without much difficulty. You can see how EF does this by referring the EntityProxyFactory and related classes, but in a gist, it’s a combination of reflection and IL Emits. NHibernate goes one step further and even supports accessing private fields (already being discussed for EF as well). However both currently require you to have a default constructor (even if it is non-public).

This general direction is good because, as Julie mentions, it promotes persistence ignorance

Architecturally, both Entity Framework and NHibernate support using patterns that help achieve persistence ignorance –

Entity framework has the DBSet and the DBContext respectively, whereas NHibernate has QueryOver api and the SessionContext. On the other hand, to support lazy loading, they also currently follow the virtual proxy pattern which goes against this principle (needs properties to be marked as virtual).

Persistence Ignorance is generally regarded as a good practice; business rules can be isolated from persistence logic, unlike, say when using Active Record pattern. This keeps the overall design simpler and more easily testable.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and dont miss out on content that matters to you

BT