NHibernate的SchemaExport工具不会创建表时"脚本"是假的 [英] NHibernate SchemaExport does not create tables when "script" is false

查看:207
本文介绍了NHibernate的SchemaExport工具不会创建表时"脚本"是假的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一步骤,NHibernate的,我试图把它从HBM文件自动创建我的表。数据库后端是SQL Server 2008的开发版。

Making my first steps with NHibernate, I'm trying to have it creating my Tables automatically from the hbm files. The database backend is SQL Server 2008 Developer Edition.

这是常见的示例code我的NHibernate教程,请参阅:

This is the common sample code I see in NHibernate Tutorials:

var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(Posting).Assembly);
new SchemaExport(cfg).Execute(false,true,false,false);

可悲的是,这是行不通的。我已经设置show_sql为true,它并没有打印出任何声明。看着SQL事件探查我看到我的应用程序连接到数据库,但什么都不做。

Sadly, this does not work. I have set show_sql to true, and it does not print out any statement. Looking at SQL profiler I see my Application connecting to the DB, but then doing nothing.

我可以修复,通过改变一个参数(脚本)设置为true:

I can fix that by changing the first parameter ("script") to true:

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

我不明白为什么。 SchemaExport工具的参数可悲的是没有真正解释(也没有.Create和.Execute之间的差异),而我想找出这个参数呢,为什么它没有使用SQL精简版(即作品也当需要的时候,即脚本是假的)

I don't understand why. The parameters of SchemaExport are sadly not really explained (also not the difference between .Create and .Execute), and I would like to find out what this parameter does, and why it's not needed i.e. when using SQL Compact Edition (that works also when script is false)

推荐答案

通过SchemaExport是hbm2ddl工具这是真正从NHibernate的功能分离的一部分。它不使用show_sql,它被用来当NHibernate的只运行

The SchemaExport is part of the Hbm2Ddl utility which is really separate from NHibernate functionality. It does not use "show_sql" which is used while NHibernate is running only.

为了让您创建模式的使用.SetOutputFile(文件名)复印件

To get a copy of the schema you create you use .SetOutputFile(filename)

这是我用的时候我希望创建一个新的数据库的方法。 我得到一个格式化的模式在MyDDL.sql文件和数据库从模式内置:

This is the method I use when I wish to create a new database. I get a formatted schema in MyDDL.sql file and the database is built from the schema:

 private void BuildSchema(Configuration config)
 {

        new SchemaExport(config)
            .SetOutputFile(_fileName + "MyDDL.sql")
            .Execute(true /*script*/, true /*export to db*/,
                     false /*just drop*/, true /*format schema*/);
 }

SchemaExport.Create仅仅是一个以Schema.Execute与刚落虚假和格式正确的。

SchemaExport.Create is just a shortcut to Schema.Execute with the just drop false and format true.

public void Create(bool script, bool export)
	{
		Execute(script, export, false, true);
	}

这篇关于NHibernate的SchemaExport工具不会创建表时"脚本"是假的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆