【问题标题】:Generate database schema from NHibernate mapping从 NHibernate 映射生成数据库模式
【发布时间】:2010-11-20 22:13:30
【问题描述】:

是否可以从 Nhibernate 映射 DLL 生成数据库模式?

我的要求是 MySQL。 如果是这样,我该怎么做?有这方面的工具/脚本吗?开源/免费软件工具?
此外,我可以使用这些工具将数据集插入/更新到数据库吗?

【问题讨论】:

    标签: .net database nhibernate code-generation


    【解决方案1】:

    您是否尝试过使用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】:

      我使用这个代码:

      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);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-29
        • 2012-05-18
        • 2016-06-14
        • 1970-01-01
        • 2010-10-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多