代码之家  ›  专栏  ›  技术社区  ›  Ben Aston

从nHibernate属性注释类型自动生成模式

  •  0
  • Ben Aston  · 技术社区  · 14 年前

    我想从用nhibernate属性注释的类型中导出一个模式。这有可能吗?

    我当前的代码在下面,不用说,它是编译的,但是预期的表 TestType 不会被创建。

    我有如下类型:

        [Serializable, Class(Schema = "test")]    
        public class TestType
        {
            [Property]
            public Guid Id { get; set; }
            [Property]
            public string Value { get; set; }
        }
    

    我的导出代码如下:

    //...
    cfg.AddAssembly(Assembly.Load("My.Assembly"));
    new NHibernate.Tool.hbm2dd.SchemaExport(NHibernateConfiguration)
                              .Execute(false, true, false); 
    //...
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   Ben Aston    14 年前

    如果您的nHibernateConfiguration对象已使用相关的类映射正确配置,那么这将起作用:

    new NHibernate.Tool.hbm2ddl.SchemaExport(NHibernateConfiguration).Create(false, true);
    

    如果在nHibernateConfiguration中没有正确设置类映射,那么将没有要创建的架构,因此看起来SchemaExport没有工作。