BT

InfoQ Homepage News ORMs And Persistence Ignorance

ORMs And Persistence Ignorance

Leia em português

This item in japanese

Lire ce contenu en français

This item in chinese

Bookmarks

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
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.

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

Community comments

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

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

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.