NHibernate可以自动从现有类创建表吗?
我对此非常陌生,但我需要从现有类创建新表而无需手动创建它们。 可以使用工具或命令行完成吗?
是的,使用nhibernate,您可以自动生成和更新模式。
var cfg = new Configuration(); cfg.Configure(); cfg.AddAssembly(typeof (aClassFromYourProject).Assembly); new SchemaExport(cfg).Execute(false, true, false, false);
更新:SchemaExport.Execute的重载选项在3.x版本中已更改。 不再需要最后一个参数。
new SchemaExport(cfg).Execute(true, true, false);