0

我怎样才能映射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。像它这样的接缝尝试为 Quantity 查找 ClassMapping,而将值部分映射为 Component。

4

1 回答 1

0
  • 第一个变体:

    1. 从 ComponentMapping 泛型类继承的单独类中的映射组件。
    2. 映射字典属性如下:

      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
        }
    ));
    
于 2014-01-27T06:38:23.997 回答