NHibernate的SchemaExport工具没有创造表 [英] NHibernate SchemaExport not creating table
问题描述
我在学习NHibernate和想提出一个测试项目。我想生成基于所述实体的表。在测试项目中,我使用的SQLite和可以看到输出:如果存在播放器删除表,但它不是事后创建表的球员。我已经通过复制Player.hbm.xml文件到该映射被找到另一个文件夹证实
在测试项目测试类:
[测试]
公共无效TestCanGenerateSchema()
{
变种CFG =新配置();
cfg.Configure(); //告诉NH的基础上的配置
cfg.AddAssembly(typeof运算(播放器).Assembly)配置本身; //发现在这个大会
新的SchemaExport(CFG).Execute(真实的,真实的,真实的)的映射信息;
}
我的测试项目Hubernate.cfg.xml:
<?XML版本=1.0编码=UTF-8>?;
<休眠配置的xmlns =金塔:NHibernate的配置,2.2>
<会话工厂>
<属性名=connection.provider> NHibernate.Connection.DriverConnectionProvider< /性>
<属性名=方言> NHibernate.Dialect.SQLiteDialect< /性>
<属性名=connection.driver_class> NHibernate.Driver.SQLite20Driver< /性>
<属性名=connection.connection_string>数据源=:内存:;版本= 3;新= TRUE;< /性>
<属性名=connection.release_mode>汽车< /性>
<属性名=show_sql>真< /性>
<属性名=proxyfactory.factory_class> NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle< /性>
<! - 映射文件 - >
< /会话工厂>
< /休眠-结构>
在Chess.Web项目我的映射文件(生成操作=嵌入的资源):
<?XML版本=1.0编码=UTF-8>?;
<休眠映射的xmlns =金塔:NHibernate的映射 - 2.2
装配=Chess.Web
命名空间=Chess.Web.Domain>
<类名=播放器>
< ID名称=ID/>
<属性名=姓名/>
<属性名=密码/>
< /班>
< /休眠映射>
任何想法?
新的SchemaExport(CFG).Execute(真实的,真实的,真正的);如果你想创建表
第三个参数可能是假的:
justDrop
如果应该只执行删除数据库对象的DDL。
I'm learning Nhibernate and am making a test project. I want to generate tables based on the entities. In the test project, I am using sqlite and can see the output: "drop table if exists Player" but it's not creating the table Player afterwards. I have confirmed by copying the Player.hbm.xml file into another folder that the mapping is being found.
Test class in the test project:
[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);
}
My Hubernate.cfg.xml in the test project:
<?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>
My mapping file in Chess.Web project (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>
Any ideas?
new SchemaExport(cfg).Execute(true, true, true);
Third parameter should probably be false if you want to create tables:
justDrop
true if only the ddl to drop the Database objects should be executed.
这篇关于NHibernate的SchemaExport工具没有创造表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!