[NHibernate] the first application configuration of NHibernate, and the first application configuration of nhibernate

Source: Internet
Author: User

[NHibernate] the first application configuration of NHibernate, and the first application configuration of nhibernate

Nhib is the next mature and open-source object relation Er (ORM) on the. Net platform ). This article describes the configuration for the first time nhibbench is used.

1. Download nhib.pdf. The latest version of nhib.pdf is NH3.3.3,: http://nhforge.org/

2. decompress the nhib.pdf package and copy the references in the Required_Bins folder to your project root directory. Make sure that the following files are included:

  

3. Add nhib.pdf. dll to your corresponding project.

  

4. Add the Mapping File. This file is an xml file that matches your Defined Object and database table fields. Generally, the name is *. hbm. xml.

5. Add Schema to the Mapping xml file. PATH is the nhibernate-mapping.xsd in the Request_Bins folder. Step: XML> Schemas> Add

  

After the Shema is added, there will be corresponding smart prompts.

  

  

<? Xml version = "1.0" encoding = "UTF-8"?> <Hibernate-mapping xmlns = "urn: nhibernate-mapping-2.2" assembly = "nhib.pdf. entity "namespace =" nhib.pdf. entity "> <class name =" Product "table =" ProductInfo "> <id name =" Id "> <generator class =" guid "/> </id> <property name = "Name"/> <property name = "Category"/> <property name = "Discontinued"/> </class> 6. Set the Build Action of the Mapping File to Embedded Resource, and Copy to OutPut Directory to Copy always. Now a simple Mapping File is configured.

  

7. Configure the nhib.pdf database file. Generally, it is named after hibernate. cfg. xml. The <mapping> node points to the assembly name of your mapping File. Like Mapping above, you can add a Schema for hibernate. cfg. xml, and the path is the nhibernate-configuration.xsd in the Request_Bins folder.

The following code uses SQL Server2008 as the Provider.

 

<? Xml version = "1.0" encoding = "UTF-8"?> <Hibernate-configuration xmlns = "urn: nhibernate-configuration-2.2"> <session-factory> <property name = "connection. provider "> nhib.pdf. connection. driverConnectionProvider </property> <property name = "dialect"> nhib.pdf. dialect. msSql2008Dialect </property> <property name = "connection. driver_class "> nhib.pdf. driver. sqlClientDriver </property> <property name = "connection. connection_string "> Server = .; database = Tempdb; uid = ***; pwd = ***; </property> <! -- Used for debugging during development --> <property name = "show_ SQL"> true </property> <mapping assembly = "nhib.pdf. entity "/> </session-factory> 

8. Set the Build Action of the hibernate. cfg. xml file to Embedded Resource and Copy to OutPut Directory to Copy always. Now, a simple NHibernate configuration is complete.

 

Reprinted please indicate Source: http://www.cnblogs.com/caoming/p/4154373.html

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.