首页新闻招聘找找看知识库
  • 回复:2 浏览:72 2015-11-26 17:13 来自 blackday

    http://files.cnblogs.com/files/anye1993/NHibernate04.rar

     我用的是2.1.2版的NHibernate

    配置文件:

    <hibernate-configuration xmlns="urn:nhibernate-confifuration-2.2">
      <session-factory name="NHibernateTest">
        <property name="dialect">NHibernate.Dialect.Sql2008Dialect</property>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string">server=localhost;database=TestDB;uid=sa;pwd=123;</property>
        <property name="show_sql">false</property>
        <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
        <mapping assembly="NHibernate.Sample.Model"/>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
      </session-factory>
    </hibernate-configuration>

    实体类映射:
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Sample.Model" namespace="NHibernate.Sample.Model">
      <class name="NHibernate.Sample.Model.Person, NHibernate.Sample.Model" table="Person" lazy="false">
        <id name="Id" type="String" unsaved-value="null">
          <column name="UserId" length="50" sql-type="nvarchar" not-null="true" unique="true"/>
          <generator class="native" />
        </id>
        <property name="Name" type="String">
          <column name="Name" length="10" sql-type="nchar" not-null="false"/>
        </property>
        <property name="Age" type="Int32">
          <column name="Age" length="4" sql-type="int" not-null="false"/>
        </property>
      </class>
    </hibernate-mapping>

     

登录后才能评论,请先登录注册