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 Code6. 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