代码改变世界

NHbernate begginner ch7 Configuration

2011-07-09 22:39  一一九九  阅读(148)  评论(0编辑  收藏  举报

Configuration is simply a way to provide NHibernate with the information it requires to connect to the database map  our classes, and generally provide us with all of its benefits.

The basic of configuration

    the ConnectionProvider  property tells NHibernate what method it needs to use to build connections. This is usually set to “ NHibernate.Connection.DriverConnectProvider”, but other providers can be used by providing the full classname of the provider or adding the assembly name if it resies outside of NHibernate.

     todo: ConnectionProvider 到底是个啥,为啥需要这个这个?

     the Dialect property lets NHibernat know whta  database “language”  it needs to speak.

      the ConnectionStringName give Nhibernate the information about how to connect to the database. The ConnectionString property accepts a string that is the actual connection string, while the connectionStringName specifies a connection string in the <connectionStrings> section of the configuration that contains the connection string.

     the ProxyFactoryClass  is used to allow NHibernate to perform lazy loading.  three basic proxy factories that com with Nhiberante are as follows :
         Nhibernate.ByteCode.LinFu.ProxyFactoryFactory Most users will be perfectly happy with the LinFu proxy factory.

         NHibernate.ByteCode.Castle.ProxyFactoryFactory   Castle DynamicProxy factory implemention was the standard Nhibernate implementions for several years, and many Nhibernate users still implement it. Castle will be useful to you if you dicide to implement the Active Record Pattern using NHibernate . The Castle project has a full implementation of this pattern using Nhibernate . you can find more information about it at http://www.castleproject.org/activerecord/
         NHibernate.ByteCode.Spring.ProxyFactroyFactory  The spring proxyfactory is used with the spring inversion of control framework, so unless you are use spring, you won’t need to use this one.

      Mapping property  is an element of assembly that contains the name of our mapping assembly.

tips:  在修改为采用app.config的时候,出现了一个错误是”{"No persister for: Ordering.Data.Contact"}”, 此时查看Configuration对象的时候,发现有个属性叫ClassMappings的Count是0,恩,难道没有加载配置么?这才想起来代码中没有加入_cfg.Configure()函数。NH应该是在这里加载了Object的映射文件,在Constructor中加载了Connection的处理方式。