小编Ben*_*Ben的帖子

NHibernate SchemaExport没有创建表

我正在学习Nhibernate,正在做一个测试项目.我想基于实体生成表.在测试项目中,我使用sqlite并且可以看到输出:"drop table if exists Player"但是之后它不会创建表Player.我已通过将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);
    }
Run Code Online (Sandbox Code Playgroud)

我在测试项目中的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>
Run Code Online (Sandbox Code Playgroud)

我在Chess.Web项目中的映射文件(Build Action = Embedded Resource):

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Chess.Web" …
Run Code Online (Sandbox Code Playgroud)

c# nhibernate nunit hibernate

4
推荐指数
1
解决办法
4048
查看次数

标签 统计

c# ×1

hibernate ×1

nhibernate ×1

nunit ×1