Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Fluent vs. Attributes

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.

like image 979
Andy White Avatar asked Mar 25 '09 03:03

Andy White


People also ask

What is the difference between NHibernate and fluent NHibernate?

Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents, you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.

Is NHibernate better than Entity Framework?

EF Core can use a ROWVERSION/TIMESTAMP column on SQL Server, or any of a list of columns, when updating a record. NHibernate offers richer capabilities, besides SQL Server ROWVERSION/TIMESTAMP, it can also use database native mechanisms such as Oracle's ORA_ROWSCN, but also timestamp or version columns.

What is NHibernate mapping?

NHibernate is an object–relational mapping (ORM) solution for the Microsoft . NET platform. It provides a framework for mapping an object-oriented domain model to a traditional relational database.


1 Answers

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.

like image 107
James Gregory Avatar answered Sep 21 '22 04:09

James Gregory