There are three ways to store NHibernate configured 1. As a separate section placed in the configuration file of the corresponding program, it will be added to the file or class library as the file name. Config, is placed in the web.config . This method must declare the NHibernate configuration section in configsetions of the configuration file, and the configuration content is read by the cfg.environment class, and all members of this class are static, and it also defines the constant of the Key value in the configuration. 2. Playing in a separate profile, default is hibernate.cfg.xml, and cfg.configuration.config () must be called when used. If it is not the default configuration file name, you must also specify the configuration file name. This approach is best for a multi-database that can create a configuration file for each database. 3. Manual is joined in the program, and the configuration content will be added to the cfg.configuration.properties property, this property is an IDictionary object, and for public, the rest is not available. Here are a few important Key values:
Hibernate.Connection.Provider
Connection provider, the value must be a full name of the class that implements the IconnectionProvider interface, and the current version can only value NHibernate.Connection.driverConnectionProvider;
Hibernate.Connection.driver_class
Data driver class, the value must be a full name of the class that implements the idriver interface, and the common choice is NHibernate.driver.sqlclientDriver, NHibernate.Driver.OleDBDriver, etc .;
Hibernate.Diact
Database dialects, the value must be the full name of the class of Dialect, the most commonly used is NHibernate.Dialect.msql2000Diact, and other useless, unclear can not be used normally;
Hibernate.connection.connection_string
Connect strings, values are corresponding to Driver_Class;
Hibernate.show_sql
Indicates whether the SQL statement is displayed in the log4net log, mainly for debugging, value TRUE or FALSE;
Complete Configuration KEY list See Constant declaration in the CFG.Environment class. Persistent object mapping file
NHibernate provides us with a lot of ways to add a persistent object mapping file to the CFG.Configuration class, below: AddXMLFile: Add files including object mapping information; addXmlString: Add a string containing mapping information; addDocument: join Contains XMLDocument; addINputStream: Add input stream containing mapping information; addXmlReader: Add XMLReader containing mapping information; addResource: Add to specify the map information resources of the specified assembly; addClass: Join the mapping information specified by class names, mapping files Must be classname.hbm.xml; addassembly: Ampported map information resource for the specified assembly name
Note: If the mapping information is file form, including the file added to the assembly resource, the file name must end with .hbm.xml.