NHibernate.cfg.xml文件总结

  

,一个。问题:

,,, NHibernate.cfg。用xml来干什么的?


,,,,答:

,,,,,,,,配置数据库的基本信息和配置和sessionFactory实例的基本信息的配置文件。

,,,,

,B。如何配置NHibernate.cfg。xml文件?


,,,,答:

<李>

第一种方式

,,,,配置配置=新配置();

,,,,这种配置方法将会到应用程序配置文件(App.Config web . config)中查找NHibernate的配置信息,NHibernate的配置节必须符合应用程序配置文件个格式。

,,,,下面是该种方式的一个例子:

,,,,

& lt; ? xml  version=" 1.0 ",编码=皍tf - 8”, ?比;   & lt; configuration>   & lt; !——, Add 却;能够element ——比;   & lt; configSections>   ,,,& lt; section  name=" hibernate配置,type=" NHibernate.Cfg.ConfigurationSectionHandler, NHibernate "/比;   & lt;/configSections>      & lt; !——, Add 却;能够element ——比;   & lt; hibernate-configuration  xmlns=" urn: nhibernate -配置- 2.2”比;   & lt; session-factory>   & lt; property  name=胺窖浴弊4荖Hibernate.Dialect.MsSql2005Dialect   & lt; property  name=" connection.provider祝辞NHibernate.Connection.DriverConnectionProvider   & lt; property  name=" connection.connection_string祝辞服务器=TLSZ207/SQLEXPRESS; initial 目录=测试;Integrated 安全=true   & lt;/session-factory>   & lt;/hibernate-configuration>   & lt; !——, Leave 从而system.web  section  unchanged ——比;   & lt; system.web>   & lt;/system.web>   & lt;/configuration>

2。第二种方式

,,,,配置配置=新配置().Configure ();

& lt; ? xml  version=" 1.0 ",编码=皍tf - 8”, ?比;   & lt; hibernate-configuration , xmlns=" urn: nhibernate -配置- 2.0”,在   ,& lt; session-factory  name=癕ySessionFactory”比;   ,,,,,,,,,,,,,& lt; !——, properties ——比;   ,,,,,,,,,,,,,& lt; property  name=" connection.provider祝辞NHibernate.Connection.DriverConnectionProvider   ,,,,,,,,,,,,,& lt; property  name=" connection.driver_class祝辞NHibernate.Driver.SqlClientDriver   ,,,,,,,,,,,,,& lt; property  name=" connection.connection_string祝辞服务器=localhost; initial 目录=Hibernate; Integrated 安全=SSPI   ,,,,,,,,,,,,,& lt; property  name=" show_sql祝辞false   ,,,,,,,,,,,,,& lt; property  name=胺窖浴弊4荖Hibernate.Dialect.MsSql2000Dialect   ,,,,,,,,,,,,,& lt; property  name=" use_outer_join祝辞true   ,,,,,,,,,,,,,& lt; property  name=" query.substitutions祝辞true  1, false  0,, yes ‘Y’,, no  ' N ' & lt;/property>      ,,,,,,,,,,,,,& lt; !——, mapping  files ——比;   ,,,,,,,,,,,,,& lt; mapping 装配=癟est.Model”,/比;   ,,,,,,& lt;/session-factory>   & lt;/hibernate-configuration>




NHibernate.cfg.xml文件总结