【问题标题】:Wrong number of columns after converting to Table Per Concrete Class转换为每个具体类的表后的列数错误
【发布时间】:2013-08-14 21:23:33
【问题描述】:

我采用了一个工作实体类和映射并转换为使用基类。

由于这样做,我得到“NHibernate.MappingException:属性映射的列数错误:”在下降类中的任何复合用户类型上:

public SubModel : TreeNodeBase
{
   string Name { get; set; }
   Quantity Gross { get; set; }
}

public class SubModelMapping : SubclassMap<SubModel>
{
    public SubModelMapping()
    {
        Table("SubModel");

        Abstract();

        Map(x => x.Name); //normal types are fine

        Map(x => x.Gross) //this causes the error
            .LazyLoad()
            .CustomType<QuantityCompositeUserType>()
            .Columns.Clear()
            .Columns.Add("Gross_Scalar", "Gross_UoM");
    }
}

public class TreeNodeBaseMapping : ClassMap<TreeNodeBase>
{
    public TreeNodeBaseMapping()
    {
        //We are using Table Per Concrete Class inheritance

        // indicates that this class is the base
        // one for the TPC inheritance strategy and that 
        // the values of its properties should
        // be united with the values of derived classes
        UseUnionSubclassForInheritanceMapping();

        Id(x => x.Id);
        Map(x => x.Level);
        References(n => n.Parent)
            .LazyLoad()
            .Nullable();
        HasMany(n => n.Children)
            .KeyColumn("Parent_id")
            .Where(x => x.Parent.Id == x.Id)
            .LazyLoad();
    }
}
  • 在我更改为 TPCC 继承之前工作。
  • 如果我删除任何复合用户类型映射,则可以使用。

知道是什么原因造成的吗?如果可能,可以提供QuantityCompositeUserType

编辑 它创建的 SQL:

create table SubModel(
   Id UNIQUEIDENTIFIER not null,
   Name TEXT,
   Gross_Scalar NUMERIC,
   primary key (Id)
)

您可以看到预期的列 Gross_UoM 完全丢失了。

如果这是普通的ClassMap,而不是SubclassMap

create table Transactions (
   Id UNIQUEIDENTIFIER not null,
   Name TEXT,
   Gross_Scalar NUMERIC,
   Gross_UoM TEXT,
   primary key (Id)
)

【问题讨论】:

    标签: c# nhibernate fluent-nhibernate


    【解决方案1】:

    这似乎是一个老错误。

    从 github 签出并构建源代码解决了该问题。

    nuget 版本是 2012 年 6 月发布的,因此非常过时。我会询问开发人员何时计划将此类修复程序发布到 nuget,并将他们所说的发布在这里。

    【讨论】:

      猜你喜欢
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-13
      • 2021-07-24
      • 2011-12-31
      • 1970-01-01
      相关资源
      最近更新 更多