Turn from: http://www.dotnetjalps.com/2013/09/asp-net-mvc-nhibernate-crud-getting-started.html
In this post we are going to learn how we can use the NHibernate in asp.net MVC application.
What is NHibernate:
Orms (Object relational Mapper) are quite popular this. ORM is a mechanism to map database entities to Class entity objects without writing a code for fetching data and write som e SQL queries. It automatically generates SQL Query for us and fetch data behalf on us.
NHibernate is also a kind the Object relational Mapper which is a port of popular Java ORM Hibernate. IT provides a framework for mapping the domain model classes to a traditional relational databases. Its give us freedom of the writing repetitive ado.net code as this is the act as our database layer. Let ' s get started with NHibernate.
How to Download:
There are two ways can download this ORM. From NuGet package and the source Forge site. Nuget-http://www.nuget.org/packages/nhibernate/source forge-http://sourceforge.net/projects/nhibernate/Creating a table for CRUD:
I am going to use SQL Server Express Edition as a database. Following is a table with four fields Id, the name of the, and the designation.
creating ASP.net MVC project for NHibernate:
Let's create a asp.net MVC project for NHibernate via click on file-> New project–> asp.net mvc 4 Web application.
installing NuGet Package for NHibernate:
I have installed NuGet package from package Manager console via following Command.
It would install like following.
nhibertnate configuration file:
Nhibernate needs one configuration file for setting database connection and other details. You are need to create a file with ' Hibernate.cfg.xml ' in Model Nhibernate folder of your application with following details.
? XML version = "1.0" encoding = "Utf-8"?> < hibernate-configuration xmlns = "urn:nhibernate-configuration-2.2" > < Session-factory > < property name = "Connection.provider" > |