Hands on ConfORM: first steps
Days ago in one of my previous posts I talked about ConfORM, let’s see in this very short post how you can put it in action in a very simple test project.
We’ll start by creating a function to configure NHibernate:
private static Configuration ConfigureNHibernate() { var configure = new Configuration(); configure.SessionFactoryName("Demo"); configure.Proxy(p => { p.Validation = false; p.ProxyFactoryFactory<ProxyFactoryFactory>(); }); configure.DataBaseIntegration(db => { db.Dialect<MsSql2008Dialect>(); db.Driver<SqlClientDriver>(); db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote; db.IsolationLevel = IsolationLevel.ReadCommitted; db.ConnectionString = ConnectionString; db.Timeout = 10; db.HqlToSqlSubstitutions = "true 1, false 0, yes 'Y', no 'N'";
#nhday - after event thoughts
It’s time for some sparse thanksgiving, thoughts and impressions about the event.
In the first place I have to thank all the developers that stood up and took part as speakers: Oren Eini (Ayende), Rob Ashton, Gian Maria Ricci, Andrea Saltarello, Alberto Brandolini, Igor Antonacci, Luca Milan, Alberto Dallagiacoma and myself Alessandro Giorgetti (why not?!?!?).
I couldn’t follow the sessions on the second track even if they were extremely appealing...we however have the videos and maybe we can ask the guys to replicate them in some other community workshop we can organize.
A very special thank goes to Oren Eini and Rob Ashton, it was an honor and a privilege for me to meet you two face to face. It’s very rare to find guys so kind, friendly and passionate for their work as you two are. Seeing you working on RavenDB features during the presentations (while answering other people’s questions) and during our after dinner event with an absolutely crazy brainstorming session was something that you cannot see every day...sometimes I wondered how you could follow the whole conversation with one topic shot right after another without even finishing the previous one...jumping back and forth between different ideas .
Also a huge thank to Fabio Maulo who couldn’t come here from Argentina, but who agreed to be available the WHOLE day, whenever we called him for the Q&A session.
Speaking of the main track..well it was mainly a ‘one man show’ by Oren, who covered different aspects of the new NHibernate 3 between hidden gems (a couple I didn’t knew really) and worst practices.
We also had a session about how the new Linq to NHibernate provider is built and what you can do with it, hosted by my good fellow Gian Maria Ricci - perfect as ever - and myself (yay! I managed to survive it!).
As always happens the Q&A session (with Fabio Maulo as special guest via skype call) started slowly in the beginning...people have to win the shyness , but then it skyrocketed and we had to stop the flow of questions due to the time limit.
To close the event we had a bonus session on RavenDB that made me very curious to try it and see if it can fit for some of my applications.
I couldn’t follow the second track session, so I do not have direct feedback from them yet, but according to what Rob wrote on his post event blog-post, some crazy and funny things happened there too.
I have to say it was a good event, I’ve learned new things, meet vey nice guys, made good laughs and I’m pleased to have took part in it. I also think we can improve the experience for maybe future editions.
In the end a big thank goes to all the guys in the audience that came to see the event, I didn’t expected to have so many people.
We’ll manage to publish the slides and the videos we recorded about every track on our blogs and community websites (DotNetMarche, UGIALT.net) as soon as the post-production step is completed, for now you can see the steaming recorded videos at the UStream.tv channel we created to broadcast the event: http://www.ustream.tv/channel/nhday-main-room.
All the samples used for the Linq To NHibernate track are available at this CodePlex project: http://nhday.codeplex.com/ we’ll add the code samples or reference to them about the other tracks as soon as we can collect them.
What’s missing? oh yeah...some photos of the event...I’ll update this post as soon as I have them.
Related Content
- Breaking news: the First European NHibernate Day had been officially announced (26/08/2015)
- The NHibernate Day is coming...this Saturday! (10/06/2010)
- NHibernate - First impressions on ConfORM (26/08/2015)
- NHibernate - Customize the Linq provider to call your user defined SQL functions (10/01/2010)
- Hands on ConfORM: mixed mapping techniques (26/08/2015)
- More related document (21)
The NHibernate Day is coming...this Saturday!
If you’re a fan of NHibernate, if you use it for your everyday work or just if you are curious about it, you should have not missed to register for the first European NH Day coming up this Saturday.
The Agenda is quite rich, various and with very interesting topics...it promises to be a very exciting day.
Personally I’m looking forward to meet personally some of the guys whose blogs I read on a regular basis. I’m just sad we cannot have Steve Strong presenting the Linq to NHibernate session as announced when we organized the event at first...this ‘forced’ my good fellow Alkampfer and me to step up and cover the hole.
For more info and constant updates on the event head to: http://www.nhday.eu/en.aspx
To follow us on twitter the hashtag is: #nhday
See you there...I’m sure we’ll have a great day together.
Related Content
- Breaking news: the First European NHibernate Day had been officially announced (26/08/2015)
- #nhday - after event thoughts (10/11/2010)
- NHibernate - First impressions on ConfORM (26/08/2015)
- NHibernate - Customize the Linq provider to call your user defined SQL functions (10/01/2010)
- Hands on ConfORM: mixed mapping techniques (26/08/2015)
- More related document (21)
NHibernate - Customize the Linq provider to call your user defined SQL functions
Let’s see how you can extend the new Linq to NHibernate provider to call your custom defined SQL functions.
First off let’s start defining a custom function we want to call:
CREATE FUNCTION [dbo].[CustomGetMonth] ( -- Add the parameters for the function here @date datetime ) RETURNS int WITH EXECUTE AS CALLER AS BEGIN -- Return the result of the function IF @date IS NULL RETURN 0 RETURN Datepart(mm,@date)
NHibernate - First impressions on ConfORM
I was very curious when I’ve heard of this project, I’ve used FluentNHibernate as my API to generate mappings in the past, it has its strong and weak points, things I like and things I don’t like much (personal opinions)...so I decided to give ConfORM a try to see how this other option we have works...using a very simple project (like the one I’ll use on my next ‘Linq to NHibernate’ speech at NHDay).
I’ll start with a basic consideration: for legacy databases I still prefer the usual XML mapping for a series of different reasons, but mainly due to the number of special cases you can face during the mapping and I think that the XML representation is more clean and compact to read than anything mapped with an API.
That said, let’s go back to ConfORM. At start I was a bit confused about how ConfORM worked, until I realized that it was following a completely different approach compared to what we were used to do.
ConfORM isn’t just another API that allows you to map you domain classes in NHibernate mimic what you can already do with XML files...it offers you a complete new way of thinking how mapping should be done.
Putting it simple the idea is:
- You have a set of domain classes.
- You have your persistence engine (NHibernate).
- You want a system you can instruct with a series of rules and exceptions that take care of discovering and generating the mappings that describe your domain classes to NHibernate.
This is ConfORM!
And just speaking of it I see a very wide range of possibilities in its application, especially if you have full control over your database, just think of it:
- Once you have defined your mapping rule-set you can add new classes and have them mapped for free (almost, you always have to deal with exceptions, special cases or fine tunings, but the impact should be minimal).
- No more directories filled with .hbm.xml files anymore.
- No more projects or code files dedicated to hold you code mapping files.
- Consistency in the naming conventions of all the objects that will be generated in the database (if you let NHibernate generate them).
- You can apply different mapping patterns for different portions of your domain easily.
- The system itself is highly extensible and you can implement your own patterns starting from those already present.
- Improved startup time: we can jump over all the XML loading and deserialization stage because ConfORM directly emits NHibernate metadata mappings classes.
Those are some of the things that came into my mind after playing with it for just a couple of days. You need some time to get into the ConfORM view of doing things and it cannot be applied easily to every scenario, especially when dealing with legacy databases (even if it’s flexible enough, but you’ll end up mapping too many exceptions), but it’s another tool we have to define our mappings and I have to say it really impressed me.
The major drawback actually is that the project is in beta stage (but it seems solid enough already) and suffer of a lack of documentation (you can find some introductive posts on Fabio Maulo’s blog and download the whole codebase which contains example of usage...don’t forget it’s another open source project).
In the end of this free talk I asked myself a question: will I use it to define my mappings in production code ? I will for sure give it a serious chance because I really like the approach and I think that with very huge domains, once I got the grasp on it, it can definitely be a time (and life) saving tool.
Related Content
- Hands on ConfORM: mixed mapping techniques (26/08/2015)
- NHibernate ConfORM Mapping Explorer (26/08/2015)
- NHibernate Mapping Explorer Preview 2 (12/06/2010)
- Breaking news: the First European NHibernate Day had been officially announced (26/08/2015)
- NHibernate - Customize the Linq provider to call your user defined SQL functions (10/01/2010)
- More related document (21)
NHibernate - a custom IUserType to perform static lookup
A common problem when dealing with enterprise line of business applications is trying to minimize the access to the database, recently I was working a project that used NHibernate as its persistence layer and that was doing lots of queries to the database to just load some lookup table; the situation was similar to the following:
You have an entity that defines a list of choices a user can make, in out example we just call it ‘ListItem’, you then have another entity (we call that EntityUsingListItem) that just uses this ListItem class and can have a reference to a single ListItem or to a list of ListItem (this simulate the possibility for the user to select a single item or more items from a selection control); the user cannot add any element to the original ListItem collection; here are our test class:
public class EntityUsingListItem { public EntityUsingListItem() { List = new List<ListItem>(); }