C# NHibernate 可以自动从现有类创建表吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/815854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can NHibernate create tables from existing classes automatically?
提问by mkelley33
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?
我对此很陌生,但我需要从现有类创建新表,而无需手动创建它们。这可以使用工具或命令行完成吗?
采纳答案by Daniel Auger
Yes, with nhibernate you can generate and update schemas automatically.
是的,使用 nhibernate,您可以自动生成和更新模式。
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof (aClassFromYourProject).Assembly);
new SchemaExport(cfg).Execute(false, true, false, false);
Update: The overload options for SchemaExport.Execute have changed in the 3.x versions. The last argument is no longer needed.
更新: SchemaExport.Execute 的重载选项在 3.x 版本中已更改。不再需要最后一个参数。
new SchemaExport(cfg).Execute(true, true, false);