NHibernate or Fluent NHibernate? [closed]
Asked Answered
R

5

35

I would be interested in hearing op opinions from others regarding whether which they would choose (no 'neithers' please ;), and why.

What are the downsides to using fluent? (version dependancy maybe?) Pros, Cons, Experiences etc.

Runway answered 29/8, 2009 at 9:3 Comment(2)
hbm.xml file is used in NHibernate for mapping but Fluent NHibernate replaces it in C# code. It is very easy to find issue and maintain.Seedcase
I ask this over 3 years ago, and it gets closed this month? huh.Runway
E
52

Fluent NHIbernate sits on top of NHibernate, so its not really a choice between the two. If youre going to use NHibernate, CHOOSE to use Fluent NH on top of it to save yourself vast amounts of effort.

Fluent NHibernate is awesome, I wouldn't use NHibernate without it. You can fluently map all your entities (giving you compile time checking, and automated testing support) instead of having to maintain cumbersome xml files and remember their syntax/DTD.

It can also automatically map your entities based on default and/or your own custom conventions.

Just use it!

Ednaedny answered 29/8, 2009 at 9:12 Comment(5)
Yes, sorry I should have phrased my question slightly differently ;) Thanks for the answer.Runway
Yes I couldn't agree more. We've used Fluent alongside Rhino and the Geo libraries. We do occasionally come across version discrepancies!Weatherproof
I second that. I just started using Fluent NHibernate, and I don't (won't) look back. It is just amazing how easy it is to map your classes.Inspire
Is that true, that fluent isn't supported anymore?Trainbearer
@Trainbearer it's still not dead however development slowed down a lot since Mapping by Code enters the playground.Humanitarian
M
13

I would definitely say go with fluent-nhibernate. Just be aware it may not necessarily be as smooth a ride as you would hope.

  1. Regarding version dependency

    1. I have had a 'reverse' dependency issue when upgrading to a new version of FNH required me to upgrade to a new version of NH (2.0 to 2.1 I think). This was not a major issue for me.
    2. I just recently (this morning) dropped NH 2.1.1 into the FNH 1.0 RTM (this is distributed with 2.1.0) without any dramas (yet).
  2. Edit: Since writing this post FNH has matured substantially to the point where I do not think this is a real issue anymore Mapping support - some mappings are not yet possible with fluent nhibernate. However, this is NOT a reason to avoid FNH as hybrid fluent-xml mappings allow you to fallback on traditional xml in the event of fluent being unable to map it (although this is only on per-class granularity). Examples of mappings:

    1. Cannot yet map fields - http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/a7787927dafd23a/84ce2616946a18d7
    2. Cannot map some times of dictionary http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/d38b6c72250cd2fb - actually from what I gather this functionality exists but is not in the mainline yet.
  3. Compound complexity factor. From the sounds of it you will be learning both FNH and NH at the same time. For the majority of fairly simple applications this is fine - infact FNH is often so good that you need to know fairly little about the hbm.xml mappings. But if you want to go do something reasonably complex, it will rarely work the first time round and you are left wondering if it is a PEBKAC, fluent or NH issue. More often than I'd hoped I ended up writing the traditional xml mappings (of course, you are doing this anyway, but it would have been preferable not to expend more effort than necessary fiddling with fluent first).

Murther answered 12/11, 2009 at 3:11 Comment(5)
Thanks for your thoughts - I hear you on point 3. In the end I went with FNH, but I'm also doing a small project sans-fluent - This was a really good idea, as I feel I'm learning a lot about NH and feeling more comfortable actually knowing what's going on. (By the way I had to look up PEBKAC, but yes - this is where the majority of my problems stem from ;)Runway
Just FYI, fields are now supported in the latest version.Send
you can always generate the hbm.xml from the fluent mappings and hand edit them. No need to write all by handHumanitarian
i would add that unit testing the mapping is made easy with Fluent configuration and PersistenceSpecificationHumanitarian
Fluent still does not allow to map properties with custom parametrized types. Ran into the issue while trying to address consequences of nhibernate.jira.com/browse/NH-2528Hartsfield
O
9

The advantage of using Fluent NHibernate together with NHibernate is that you get compile time errors if you have messed up your mapping, instead of runtime errors. You also get a much better experience when refactoring your code, since your mappings are kept up to date as you rename properties or whatever, instead of having to remember to manually modify you XML mapping files.

The biggest downside of Fluent NHibernate is that it is still in a quite early phase of its development, and there is quite a big risk of breaking changes as the development of the framework progresses.

Opposite answered 29/8, 2009 at 9:25 Comment(1)
In my experience, most of the errors due to bad mappings I encounter using FluentNHibernate occur at runtime, when NHibernate is first used in the application. Only simple refactoring/type mismatches/mispellings/etc. will cause compile time errors.Undersea
A
4

Personally I havent really gotten much into fluent nhibernate as I am comfortable with the mapping files. using visual studio to create the mapping files is a breeze and you can set the schema for the xml file which gives you intellisense on the the mapping file. I agree that having compile-time syntax checking is an advantage to using fluent-nhibernate, but I struggle justifing learning the fluent API when I already am familiar with the XML mapping. Perhaps I should just get over my lethergy and learn it already... :-)

Ataractic answered 5/11, 2009 at 11:44 Comment(0)
C
2

Fluent N-Hibernate is really a nice wrapper over NHibernate. To manage mapping in Fluent much better than xml mapping. Development become fast as you get on to Fluent...

Best if you use Entity Developer for creating entity and Database schema.

Cliffcliffes answered 8/11, 2012 at 6:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.