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

时间:2010-08-12 17:21:25

标签: c# nhibernate database-schema

我想从使用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 个答案:

答案 0 :(得分:0)

如果已使用相关的类映射正确配置了NHibernateConfiguration对象,则可以使用:

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

如果在NHibernateConfiguration中没有正确设置类映射,那么将不会创建架构,因此SchemaExport将无法正常工作。

相关问题