Nhib.pdf Configuration
There are three methods to store Nhibernate configurations.
1. Put it as a separate section in the configuration file of the corresponding program. Add. config to the name of the execution file or class library, and put Asp.net in Web. config. In this way, the configuration section of Nhibernate must be declared in configsetions of the configuration file,
The configuration content is read by the cfg. Environment class. All the members of this class are static. In addition, it defines the constant of the key value in the configuration.
2. Put it in a separate configuration file. The default value is hibernate. cfg. xml. cfg. configuration. config () must be called during use (). If it is not the default configuration file name, you must specify the name of the configuration file. This method is most suitable for multiple databases. You can create a configuration file for each database.
3. manually add the configuration content to the program. The configuration content will be added to the cfg. configuration. properties attribute. This attribute is an idictionary object and is public. You don't need to talk about the rest.
The following describes several important key values:
-
Hibernate. Connection. Provider
-
Connection provider. The value must be the full name of the class that implements the iconnectionprovider interface. The current version can only be set to nhib.pdf. Connection. driverconnectionprovider;
-
Hibernate. Connection. driver_class
-
Data driver class. The value must be the full name of the class implementing the idriver interface. Commonly Used options include nhib.pdf. Driver. sqlclientdriver and nhib.pdf. Driver. oledbdriver;
-
Hibernate. Dialect
-
Database dialect. The value must be the full name of the inherited dialect class. The most common value is nhib.pdf. dialect. mssql2000dialect. It is no longer used, and it is unclear whether it can be used normally;
-
Hibernate. Connection. connection_string
-
The connection string. The value corresponds to driver_class;
-
Hibernate. show_ SQL
-
Indicates whether to display SQL statements in log4net logs. It is mainly used for debugging and the value is true or false;
For the complete configuration key list, see the constant declaration in the cfg. Environment class.
Persistent Object ing File
Nhibernate provides us with many ways to add Persistent Object ing files to the cfg. configuration class, which are listed one by one below:
Addxmlfile: Add a file that includes Object ing information;
Addxmlstring: a string containing the ing information;
Adddocument: xmldocument that includes the ing information;
Addinputstream: An input stream that includes ing information;
Addxmlreader: xmlreader that includes ing information;
Addresource: add the ing information resource of the specified assembly;
Addclass: adds the ing information resource specified by the class name. The ing file must be classname. HBM. xml;
Addassembly: add the ing information resource of the specified Assembly name
Note: If the ing information is in the file format, including the file added to the Assembly resource, the file name must end with. HBM. xml.