Generate database schema from NHibernate mapping

故事扮演 提交于 2019-12-20 20:34:15

问题


Is it possible to generate the database schema from the Nhibernate mappings DLL?

My requirements is for MySQL. If so, how do I do that? Are there tools/scripts for this? Open source/freeware tools?
Additionally, can I use these tools to insert/update datasets to the database?


回答1:


Have you tried using NHibernate's built-in schema generation tool?

var cfg = new NHibernate.Cfg.Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(AnEntityInYourMappingLib).Assembly);
new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Execute(false, true, false, false);



回答2:


I use this code :

public void CreateDatabaseSchemaFromMappingFiles()
{
    NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
    cfg.Configure();
    NHibernate.Tool.hbm2ddl.SchemaExport schema = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg);
    schema.Create(false, true);
}


来源:https://stackoverflow.com/questions/1299373/generate-database-schema-from-nhibernate-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!