0

How can I map IDictionary<Entity, Component>? I've done this way:

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()));

(where GeneralResourceType is a mapped Entity and Quantity is a ValueObject). But during the call of BuildSession() exception is thrown:

NHibernate.MappingException : An association from the table BookedResources refers to an unmapped class: {MyNamespace}.Quantity. Seams like it tries to find ClassMapping for Quantity, while value part mapped as Component.

1 Answers1

0
  • First variant:

    1. Map component in separate class inherited from ComponentMapping generic class.
    2. Map dictionary property as follows:

      Map(x => x.BookedResources, c =>
      {
          //any options access, cascade etc
      });
      
  • Second variant (inline):

    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
        }
    ));