gpt4 book ai didi

c# - NHibernate SchemaExport 不创建表

转载 作者:太空狗 更新时间:2023-10-30 00:32:49 25 4
gpt4 key购买 nike

我正在学习 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);
}

我的测试项目中的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 项目中的映射文件(Build Action = Embedded Resource):

<?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>

有什么想法吗?

最佳答案

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

如果你想创建表,第三个参数可能应该是 false:

justDrop
true if only the ddl to drop the Database objects should be executed.

关于c# - NHibernate SchemaExport 不创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15346080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com