1

I have the following class with a Dictionary :

public class Entity1 
{
    public Dictionary<Entity2,Entity3> Targets { get; set; }
}

Mapped currently by this code :

    Map(x => x.Targets,
        m => m.Key(k => k.Column("Entity1ID")),
        km => km.ManyToMany(mtm => mtm.Column("Entity2ID")),
        vm => vm.ManyToMany(mtm => mtm.Column("Entity3ID")));

I am looking for a way to set different cascade option to the KeyMapping, and a different one to the ValueMapping. But i can find cascade only in the main "Collection Mapping"

I want the key to have Cascade.None - because a different part of the application manages that entity, and the Value to have Cascade.AllDeleteOrphan.

How can i do that with MbC ?

plus - if i set the "CollectionMapping"'s Cascade - to what Entity does it reflect?

I am using the latest Nhibernate on nuget.

Royi Mindel
  • 1,258
  • 12
  • 35

1 Answers1

2

AFAIK Cascading options on Collections only effect the values of the collection. Having Cascade.All on the collection:

var e2 = new Entity2();
using (var tx = session.BeginTransaction())
{
    session.Save(e2);

    session.Save(new Entity1 { Dictionary = { { e2, new Entity3() } } }); // should work
    session.Save(new Entity1 { Dictionary = { { new Entity2(), new Entity3() } } }); // does not work

    tx.Commit();
}
Firo
  • 30,626
  • 4
  • 55
  • 94
  • that didn't answer the question of how to map different cascade for the key, plus i am more concerned about the Delete cascading of the key/value in the map (I can check the default cascading myself, i want to know how to configure it) – Royi Mindel Nov 04 '13 at 18:11
  • since cascading doesn't affect the key of the map it is basicly `Cascade.None` for the key. It is not possible to set cascading for the key of a collection – Firo Nov 05 '13 at 08:03