Getting Started with NHibernate and asp.net Mvc-crud operations__.net

Source: Internet
Author: User
Tags sql server express

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" >
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.