NHibernate的可以创建自动现有类表? [英] Can NHibernate create tables from existing classes automatically?

查看:148
本文介绍了NHibernate的可以创建自动现有类表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个非常新的,但我需要,而无需手动创建它们创建从现有类新表。可以这样使用工具或命令行来完成?

I'm very new at this, but I need to create new tables from existing classes without creating them by hand. Can this be done using a tool or command line?

推荐答案

是,与NHibernate可以自动生成和更新模式。

Yes, with nhibernate you can generate and update schemas automatically.

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



更新:对于SchemaExport.Execute过载选项已在3.x版本的改变。 。最后一个参数不再需要

Update: The overload options for SchemaExport.Execute have changed in the 3.x versions. The last argument is no longer needed.

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

这篇关于NHibernate的可以创建自动现有类表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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