如何映射IDictionary<Entity, Component>
?我这样做了:
Map<GeneralResourceType, Quantity>(x => x.BookedResources,
c =>
{
c.Key(ck => ck.Column("ProposedAction"));
c.Table("BookedResources");
},
k => k.ManyToMany(key => key.Column("ResourceTypeId")),
r => r.Component(qc => QuantityMapping.Mapping()));
(其中GeneralResourceType是映射的实体,Quantity是ValueObject)。但是在调用BuildSession()时会抛出异常:
NHibernate.MappingException:来自BookedResources表的关联引用了一个未映射的类:{MyNamespace} .Quantity。 像它这样的接缝试图找到数量的ClassMapping,而值部分映射为Component。
答案 0 :(得分:0)
第一个变种:
映射字典属性如下:
Map(x => x.BookedResources, c =>
{
//any options access, cascade etc
});
第二个变体(内联):
Map(x => x.BookedResources, x =>
{
//any options access, cascade etc
},
x => x.Element(),
x => x.Component(c =>
{
c.Class<Quantity>();
c.Property(p => p.Amount);
c.Property(p => p.Unit);
// any other properties
}
));