views:

447

answers:

5

I just want to do a quick poll to see if Fluent Nhibernate is well received or if it is having lot of issues. I like Nhibernate but I definitely see the problem with xml to do mapping.

So, I am looking forward to community members for some insight and help me pick one over the other.

I am not considering either linq2sql or entity framework at this time.

+5  A: 

One of the best advantages of using Fluent Nhibernate over vanilla NH is nice integration testing with PersistenceSpecification<T>:

[Test]  
public void TestProductSave()  
  {  
   new PersistenceSpecification<Product>()  
      .CheckProperty(x => x.ProductName, "Wax")  
      .CheckProperty(x => x.Price, 20)  
      .VerifyTheMappings();  
  }
Bayard Randel
A: 

I've been using fluent on a new project of mine. The only minor bump I've hit so far is that it doesn't play so well with Castle Windsor out of the box, but it was quite easy to extend Windsor to do the job. Other than that I've been loving it. It's much more concise than the XML mappings.

The nice thing about fluent is that it isn't an all or nothing investment. You can write most of your mappings in fluent and if you find any issues you can map those classes in the standard XML mapping until the fluent issues are resolved.

EvilRyry
+11  A: 

I like Fluent NHibernate and I think it's mature enough if you are going to start a new project. Using it on a new project should allow the Fluent NHibernate project to continue to mature as yours progresses. There is a possibility for breaking changes (as happened recently with the convention mappings) but you should be able to deal with those. I've had a few issues with the mappings but the project is pretty responsive to bug reports and has mostly worked as expected.

The mapping options are:

  • Xml mappings - Standard of NHibernate. The maintenance headaches are well known but the advantage is that you have access to all of the configuration options provided by NHibernate. There are a few less-used configuration options are still being added to Fluent (at least last time I paid attention). So, if you are anticipating some crazy mappings, you may want to consider this option.

  • Standard Mapping - Provided by Fluent. You can create the mappings through code and is much better for refactoring and authoring. Not much to say about it, in my experience, other then that it works well and is a big improvement on the xml option.

  • Auto Mapping - Provided by Fluent. Allows you to map object properties by convention and it attempts to create the mappings automatically. It's a good idea but I think it still has some maturing to do. I'm currently using this mapping method and it works fine but I have ended up writing a large number of conventions and specifying the object relationships that it doesn't feel like it's saved much effort from the standard mappings.

Fluent NHibernate also provides nice test helpers for testing your mappings and some configuration APIs that can make it easier to configure NHibernate. Overall, it's a good project and it provides some nice additional functionality to NHibernate.


edit:

One additional thing to note: If you start off with Fluent NHibernate and decide it isn't going to work for your scenario, you can easily migrate back to the xml mappings. Fluent NHibernate allows you to export the mappings it creates and you can use those exports to not lose whatever mapping work you've already done.

Steven Lyons
A: 

I am using FNH for a new project. What I like the best is the ability to generate and build the database directly from the entity classes.

I have had to write a few conventions for the properties but I'd rather that then maintain more than one list for each class.

Maggie
+1  A: 

Like any good answer, it depends.

I didn't get as much mileage out of the automapping features as I would have wanted to. I often have to work with preexisting databases.

I already had several projects using NHibernate under my belt, so using the hbm mapping wasn't difficult. After I figured out how to include in the hbm schema, it was much easier.

The one real advantage I gained from having fluent-nhibernate is being able to refactor my domain classes and have my mappings automatically change. I didn't really notice that much of a speed increase in writing the mappings.

Like anything, YMMV.

Min
+1 for the refactoring advantage, especially combined with automapping. I can see how overriding default conventions can still require some time, but at least I can refactor and re-generate the hbm files, minimizing manual tuning/customization at the XML level.
David Cuccia

related questions