4

私は Nhibernate を学んでおり、テスト プロジェクトを作成しています。エンティティに基づいてテーブルを生成したい。テスト プロジェクトでは、sqlite を使用しており、「プレイヤーが存在する場合はテーブルをドロップする」という出力を確認できますが、後でテーブル プレイヤーを作成していません。Player.hbm.xml ファイルを別のフォルダーにコピーして、マッピングが検出されていることを確認しました。

テスト プロジェクトのテスト クラス:

    [Test]
    public void TestCanGenerateSchema()
    {
        var cfg = new Configuration();
        cfg.Configure(); //tell NH to configure itself based on the config
        cfg.AddAssembly(typeof(Player).Assembly); //find mapping info in this assembly

        new SchemaExport(cfg).Execute(true, true, true);
    }

テスト プロジェクトの私の Hubernate.cfg.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
        <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
        <property name="connection.connection_string">Data Source=:memory:;Version=3;New=True;</property>
        <property name="connection.release_mode">auto</property>
        <property name="show_sql">true</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
        <!-- mapping files -->
    </session-factory>
</hibernate-configuration>

Chess.Web プロジェクトの私のマッピング ファイル (ビルド アクション = 埋め込みリソース):

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Chess.Web"
                   namespace="Chess.Web.Domain">
    <class name="Player">
        <id name="Id"/>
        <property name="Name" />
        <property name="Password" />
    </class>
</hibernate-mapping>

何か案は?

4

1 に答える 1

8
new SchemaExport(cfg).Execute(true, true, true);

テーブルを作成する場合は、3番目のパラメーターはおそらくfalseになります。

justDrop
true if only the ddl to drop the Database objects should be executed.
于 2013-03-11T21:01:05.197 に答える