【问题标题】:Autogenerating schema from NHibernate attribute annotated types从 NHibernate 属性注释类型自动生成模式
【发布时间】:2010-08-12 17:21:24
【问题描述】:

我想从我的类型中导出一个带有 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); 
//...

【问题讨论】:

  • 我正在尝试从流利的映射生成模式,在没有进一步的知识重新属性的情况下。
  • so...不是很清楚,是要使用fluent映射(fluent nhibernate)还是属性?
  • 最后我使用了属性映射。

标签: c# nhibernate database-schema


【解决方案1】:

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

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

如果没有在 NHibernateConfiguration 中正确设置类映射,那么将没有要创建的架构,因此会出现 SchemaExport 不起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 2019-03-24
    • 2016-05-05
    • 1970-01-01
    相关资源
    最近更新 更多