In ASP. in the. NET project, the use of nhib.pdf always encounters the problem of being unable to load the configuration file. Just one hour ago, I found a solution from a foreign blog. address: http://derek-says.blogspot.com/2008/02/nhibernate-in-visual-web-developer.html.
Now I will explain how to configure it.
1. Create tables in the database, such as tb_department
2. Then write the corresponding class file. For example, the full name of the corresponding class is netfuture. nhibernateclass. nh_tb_department.
3. Add the configuration in webconfig. Here is my configuration file:
<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. mssql2000dialect
</Property>
<Property name = "connection. driver_class">
Nhib.pdf. Driver. sqlclientdriver
</Property>
<Property name = "connection. connection_string">
Data Source = (local); Integrated Security = true; initial catalog = db_personnelmanagesystem
</Property>
<Mapping Assembly = "app_code"/>
</Session-factory>
</Hibernate-configuration>
The red sentence seems to be the key.
4. Write the ing file corresponding to the class, such:
<? XML version = "1.0" encoding = "UTF-8"?>
<Hibernate-mapping xmlns = "urn: nhibernate-mapping-2.2" default-Lazy = "false">
<Class name = "netfuture. nhibernateclass. nh_tb_department, app_code" table = "tb_department">
<ID name = "inclumentid" column = "inclumentid" type = "int32" length = "4" unsaved-value = "0">
<Generator class = "native"/>
</ID>
<Property name = "departmentname" column = "departmentname" type = "string" length = "16"/>
<Property name = "Description" column = "Description" type = "string" length = "200"/>
<Property name = "managerid" column = "managerid" type = "string" length = "15"/>
</Class>
</Hibernate-mapping>
The red sentence is also the key.
5. Place the class and ing files in the app_code folder.
6. Write the Initialization Configuration code similar to the following Nhibernate:
Nhibernate. cfg. Configuration CFG = new Nhibernate. cfg. configuration ();
Cfg. adddirectory (new system. Io. directoryinfo (system. Web. httpcontext. Current. server. mappath (@"~ /App_code /")));
_ Factory = cfg. buildsessionfactory ();
In this way, the apping of the app_code folder is completed, and nhib.pdf will search for the configuration file.
I want to help you write your essay for the first time.