Nhibernate和Sqlite資料庫的使用

來源:互聯網
上載者:User

hibernate.cfg.xml設定檔Sample:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory name="Rock">
    <!-- properties -->
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver, NHibernate</property>
    <property name="connection.connection_string">Data Source=D:\Data\SQLite_DB\rock.db;Version=3</property>
    <property name="dialect">NHibernate.Dialect.SQLiteDialect, NHibernate</property>
    <property name="query.substitutions">true=1;false=0</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    <property name="show_sql">false</property>
    <property name="use_outer_join">true</property>
    <!--
            these are different than the values in app.config so I can verify these
            are being picked up
        -->
    <property name="command_timeout">444</property>
    <!-- mapping files -->
    <!-- are now optional
            <mapping file="ABC.hbm.xml" />
            <mapping resource="NHibernate.DomainModel.Simple.hbm.xml" assembly="NHibernate.DomainModel" />
        -->
  </session-factory>

</hibernate-configuration>

 

自動增加主Key的Mapping的Sample:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false" namespace="Rock.Data.Model" assembly="Rock.Data.Model">
    <class name="PasswordMaster,Rock.Data.Model" table="PasswordMaster" lazy="false">

        <!-- Primary Key(s) -->
        <id name="Id" column="PwdKey" type="Int32" unsaved-value="0">
           <generator class="increment"/>
        </id>
        <!-- Properties -->
        <property column="PwdName" type="String" name="PwdName" not-null="true" length="50" />
        <property column="PwdID" type="String" name="Pwdid" not-null="true" length="50" />
        <property column="PwdValue" type="String" name="PwdValue" not-null="true" length="50" />
        <property column="WebSite" type="String" name="WebSite" length="50" />
        <property column="Q1" type="String" name="Q1" length="50" />
        <property column="A1" type="String" name="A1" length="50" />
        <property column="Q2" type="String" name="Q2" length="50" />
        <property column="A2" type="String" name="A2" length="50" />
        <property column="Q3" type="String" name="Q3" length="50" />
        <property column="A3" type="String" name="A3" length="50" />
        <property column="CreateDate" type="DateTime" name="CreateDate" not-null="true" />
        <property column="Remark" type="String" name="Remark" length="255" />
    </class>
</hibernate-mapping>

 

當然項目要引用System.Data.Sqlite.DLL這個檔案。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.