首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NHibernate SchemaExport未创建表

NHibernate SchemaExport未创建表
EN

Stack Overflow用户
提问于 2013-03-12 02:40:50
回答 1查看 4.2K关注 0票数 4

我正在学习Nhibernate,并且正在做一个测试项目。我想根据实体生成表。在测试项目中,我使用的是sqlite,可以看到输出:"drop table if exists Player“,但之后并没有创建table Player。我已经通过将Player.hbm.xml文件复制到另一个文件夹来确认已找到映射。

测试项目中的测试类:

代码语言:javascript
复制
    [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:

代码语言:javascript
复制
<?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项目中的映射文件(Build Action =嵌入式资源):

代码语言:javascript
复制
<?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>

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-12 05:01:05

代码语言:javascript
复制
new SchemaExport(cfg).Execute(true, true, true);

如果要创建表,则第三个参数可能应为false:

代码语言:javascript
复制
justDrop
true if only the ddl to drop the Database objects should be executed.
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15346080

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档