[NHibernate] application configuration for the first NHibernate

Source: Internet
Author: User

NHibernate is a mature, open source Object-relational Mapper (ORM) under the. NET Platform. This article describes the configuration when using NHibernate for the first time.

1. Download NHibernate. The latest version of NHibernate official website is nh3.3.3,:http://nhforge.org/

After extracting the 2.NHibernate compressed package, copy the references under the Required_bins folder to your project root. Ensure that the following files are included:

  

3. Add NHibernate.dll to the project you are referring to.

  

4. Add the mapping file. The file is an XML file that matches the entities you define and the database table fields. Usually named *.hbm.xml .

5. Add a schema to the mapping XML file. The path is nhibernate-mapping.xsd in the Request_bins folder. Step: Xml->schemas->add

  

After adding Shema, there will be a corresponding smart prompt.

  

  

<?xml version="1.0"encoding="Utf-8"? >"urn:nhibernate-mapping-2.2"Assembly="nhibernate.entity"                   namespace="nhibernate.entity"> <className="Product"table="ProductInfo"> <id name="Id"> <generatorclass="GUID"/> </id> <property name="Name"/> <property name="Category"/> <property name="discontinued"/> </class>View Code

6. Set the build action of the mapping file to embedded resource,copy to OutPut directory as Copy always. At this point a simple mapping file is configured.

  

7. Configure the NHibernate database file. Usually named Hibernate.cfg.xml, the booing <mapping> node points to the assembly name of your mapping file. As with the mapping above, you can add a schema for Hibernate.cfg.xml, and the path path is nhibernate-configuration.xsd in the Request_bins folder.

The following code takes SQL Server2008 as the provider.

<?xml version="1.0"encoding="Utf-8"? >"urn:nhibernate-configuration-2.2"> <session-factory> <property name="Connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property> <property name="Connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string">Server=.; database=tempdb;uid=***;p wd=***;</property> <!--development process for commissioning--<property name="Show_sql">true</property> <mapping assembly="nhibernate.entity"/> </session-factory>

8. Also say that the build action of the Hibernate.cfg.xml file is set to embedded resource,copy to OutPut directory is set to Copy always. At this point, a simple configuration of the nhibernate is complete.

Reprint please indicate source: http://www.cnblogs.com/caoming/p/4154373.html

[NHibernate] application configuration for the first NHibernate

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.