gpt4 book ai didi

c# - NHibernate SchemaExport.Execute 不创建表

转载 作者:太空宇宙 更新时间:2023-11-03 13:05:47 26 4
gpt4 key购买 nike

按照本教程学习 NHibernate Your first NHibernate based application我到了你打电话的地步 new SchemaExport(cfg).Execute(true, true, false);在导出模式(创建产品表)以验证 NHibernate 是否正确设置的测试方法中

[Test]
public void Can_generate_schema()
{
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(Product).Assembly);

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

映射

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MyFirstNHibernateProject" namespace="MyFirstNHibernateProject.Domain">
<class name="Product">
<id name="Id">
<generator class="guid"></generator>
</id>
<property name="Name"></property>
<property name="Category"></property>
<property name="Discontinued"></property>
</class>
</hibernate-mapping>

配置

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
<property name="connection.connection_string">Data Source=MyFirstNHibernateProject.sdf</property>

<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>

测试通过了,我什至可以看到创建表的输出 sql,但表没有在数据库中创建(sql server compact),我在服务器资源管理器中刷新了数据库,它仍然是空的。

我已经检查了这些帖子
NHibernate SchemaExport not creating table
NHibernate SchemaExport does not create tables when “script” is false
NHibernate does not create Tables
但他们都没有解决我的问题。有什么想法吗?

最佳答案

我建议在连接字符串中使用完整路径:

// instead of this
<property name="connection.connection_string"
>Data Source=MyFirstNHibernateProject.sdf</property>

// we should use
<property name="connection.connection_string"
>Data Source=C:\MyFirstNHibernateProject\MyFirstNHibernateProject.sdf</property>

"C:\MyFirstNHibernateProject\" 应该是 "MyFirstNHibernateProject.sdf" 的完整路径

此外,如果您要起诉 CE 4.0,我建议您使用这种方言:

<property name="dialect">NHibernate.Dialect.MsSqlCe40Dialect</property>

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

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