我已经采取了一个工作实体类和地图,并转换为使用基类。
由于这样做,我得到了"NHibernate.MappingException: property映射有错误的列数:“在user类中的任何复合用户类型上:
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();
}
}知道是什么导致的吗?如果可能相关,可以提供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)
)发布于 2013-08-14 13:23:33
这似乎是个老毛病。
检查并从github构建源代码,修复了这个问题。
nuget版本从2012年6月开始,因此非常过时。我会问开发人员什么时候他们计划发布这样的补丁给nuget,并会张贴他们在这里说的话。
https://stackoverflow.com/questions/18207274
复制相似问题