Refering:
  
http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/d38b6c72250cd2fb
  
http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/b1b335ff5f9a6a40

  I have been trying to map a ternary many-to-many association just
like above links but got some problems. After founding no way to do
that I have changed some stuff in
ManyToManyPart<TChild>.GetCollectionMapping and got that working:

  Where we have:

// child columns
if (childColumns.Count == 0)
  ((ManyToManyMapping)collection.Relationship).AddDefaultColumn(new
ColumnMapping { Name = typeof(TChild).Name + "_id" });

foreach (var column in childColumns)
  ((ManyToManyMapping)collection.Relationship).AddColumn(new
ColumnMapping { Name = column });

  I surounded with "if (collection.Relationship != null)" so I can
make the following map:


class MyEntity
{
  public IDictionary<OtherEntity,ValueType> Others { get; private
set; }
}

  The mapping:

            base.HasManyToMany<IDictionary<OtherEntity, bool>>(x =>
x.Others).Access.BackingField().
                Table("TABLE").
                ParentKeyColumn("MY_ID").
                AsMap(null).AsTernaryAssociation("OTHER_ID", "VALUE").
                Element("VALUE", x => x.Type<ValueType>());

  It produces this hbm:

    <map access="backfield" name="Others" table="TABLE"
mutable="true">
      <key>
        <column name="MY_ID" />
      </key>
      <index-many-to-many class="OtherEntity">
        <column name="OTHER_ID" />
      </index-many-to-many>
      <element type="ValueType">
        <column name="VALUE" />
      </element>
    </map>

  Without this change the GetCollectionMapping throws null reference
exception because the call "Element("VALUE", x =>
x.Type<ValueType>());" set the collection relationship to null.

  Another strange thing is that I have to use
HasManyToMany<IDictionary<,>> because in
ManyToManyPart<TChild>.AsTernaryAssociation it first calls
EnsureGenericDictionary, witch check using the private field
childType, and after use typeof(TChild).GetGenericArguments(),
throwing a "index out of bounds", and if I'm mapping
IDictionary<ValueType, OtherEntity> I have to use
HasManyToMany<OtherEntity> or else my mapping will get <many-to-many
class="KeyParValue........">.

  Regards,
  DM

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibern...@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to