Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is NHibernate and why should I use it? [duplicate]

Possible Duplicate:
What is NHibernate?

I've heard the name NHibernate used a lot, but I don't really understand what it is. I've read the Wikipedia article, but I don't understand how using NHibernate in my C# applications (desktop w/ WPF, web w/ ASP.NET MVC) will:

  • Change the code
  • Be easier/faster

Should I look into using NHibernate in my projects?


UPDATE: Thanks for identifying this as a dupe! I didn't realize that this had already been asked.

I guess my real question is about NHibernate versus Linq to SQL (which I've been using in all of my applications), but that has already been asked here and here.

Thanks, everyone! :)

like image 898
Maxim Zaslavsky Avatar asked Oct 11 '10 21:10

Maxim Zaslavsky


People also ask

What is the use of NHibernate?

NHibernate is Designed to serve as a persistence layer exclusively for the . Net framework based on Object-Relational Mapping Technique. A tool that creates a "virtual representation" of database objects within the code. Used to solve the problem of impedance mismatch between Class and relational databases and tables.

Is NHibernate better than Entity Framework?

Entity framework requires additional connections to handle databases other than MSSQL, which nHibernate provides. In terms of data loading, SQL generation, custom column types, custom collections, and so on, NHibernate can be modified. However, the entity framework has limited extension points.

What is NHibernate in .NET core?

NHibernate is a mature, open source object-relational mapper for the . NET framework. It's actively developed, fully featured and used in thousands of successful projects.

What is transaction NHibernate?

NHibernate is not itself a database. It is a lightweight object-relational mapping tool. Transaction management is delegated to the underlying database connection. If the connection is enlisted with a distributed transaction, operations performed by the ISession are atomically part of the wider distributed transaction.


2 Answers

NHibernate is an ORM (Object Relational Mapper). Its purpose is to map objects in your OO application to tables in a database for persistence.

Why would you need it? Because it can save you from writing a lot of tedious ADO.NET code. Essentially it enhances developer productivity when developing CRUD applications, that is, applications whose main purpose is to Create, Read, Update, and Delete data in a database.

NHibernate is open source, and you need to realise that you are making your application dependent on third party libraries, whose long term goals may diverge from yours.

If you want the productivity of an ORM without introducing this dependency, consider Entity Framework, or Linq2SQL (noting that Linq2SQL locks you into SQL Server).

And finally if you don't need the productivity enhancement of an ORM, and you want absolute control, stick to plain old ADO.NET.

like image 119
saille Avatar answered Oct 09 '22 10:10

saille


The main purpose of NHibernate is described in the Wikipedia article as well:

NHibernate's primary feature is mapping from .NET classes to database tables (and from CLR data types to SQL data types). NHibernate also provides data query and retrieval facilities.

NHibernate generates the SQL commands and relieves the developer from manual data set handling and object conversion, keeping the application portable to most SQL databases, with database portability delivered at very little performance overhead.

like image 44
Dirk Vollmar Avatar answered Oct 09 '22 10:10

Dirk Vollmar