I came across this post by Ayende which perfectly captures my goal for achieving persistence ignorance:
“After that, you are done. Just create an entity in the proper place, hit the /database/create and have a lot of fun.”
I particularly enjoy the “fun” part of this quote! My aim is to configure conventions and then simply code the model as I desire, allowing the framework (NHibernate in this case) to handle the storage details.
The Fluent NHibernate framework has been updated since Ayende’s post. I explored the documentation, including AutoMapping, Conventions, Available Conventions, and discovered some shortcuts. Additionally, this article explains how to transition from the old convention style to the new one.
I’ve put together an updated example inspired by Ayende’s post, including a feature for automatically setting cascades for OneToMany and ManyToMany relationships.
Here is the most important part of the code.
UPDATED Here is the complete sample.
Did I mention that I LOVE Fluent NHibernate? Well, I do!