NHibernate Fluent vs. Attributes
Asked Answered
D

2

14

I'm interested in moving some NHibernate configurations/mappings into the code to help with some maintenance issues. Can anyone provide any advice/pros/cons/comparisons of Fluent NHibernate vs. NHibernate.Mapping.Attributes?

I have some experience with Java Hibernate annotations, which I liked, but I'm curious if the NHibernate attributes are comparable, and whether Fluent provides any major upsides/downsides that should be considered.

Dayak answered 25/3, 2009 at 3:40 Comment(0)
K
19

I don't think anybody has done any outright comparisons. It falls down to how comfortable you are with decorating your entities with attributes. Fluent NHibernate is aimed at letting you use NHibernate with a completely unpolluted model, while attributes require you to alter your entities; this is a persistence concern leaking into your domain. Whether that's a problem for you is whether you should choose attributes or not.

Fluent NHibernate also throws a few more things to the table than just mappings. There's also the auto mappings which allow you to automatically map your domain. There's the conventions support which allow you to greatly reduce repetition in your design. I won't repeat everything, but you can read more on the Fluent NHibernate wiki.

Kokanee answered 25/3, 2009 at 8:54 Comment(1)
I agree with the notion of keeping the model unpolluted. This has been the biggest reason I use Fluent NHibernate, though I've used it mostly on Brownfield projects. I've just started using it in Greenfield projects and the automappings with convention support is very nice as well. To be honest, I tend to think of fluent configuration like this as a kind of aspect oriented programming, and so it has some of the same benefits as AOP.Grapnel
I
0

NHibernate now supports JPA (called NPersistence or NPA for the .NET platform) including JPA annotations. It is the best way to map your entities and have your code portable for other vendors as well. check it out:

www.npersistence.com

Infare answered 5/12, 2011 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.