Generate database schema from NHibernate mapping

后端 未结 2 1711
生来不讨喜
生来不讨喜 2021-02-08 02:07

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 th

相关标签:
2条回答
  • 2021-02-08 02:51

    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);
    }
    
    0 讨论(0)
  • 2021-02-08 03:07

    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);
    
    0 讨论(0)
提交回复
热议问题