Tried mapping that with FNH and got into a lot of problems, and eventually found out that FNH is lacking, and not maintained anymore, so i decided to try Nhibernate MappingByCode, which works so far but has no documentation...
I can't find how to map IDictionary
Map(x => x.EntityDict,
m =>
{
m.Key(k => k.Column("ParentID"));
},
km =>
{
km.//??ManyToMany
vm =>
{
vm.//??ManyToMany
}
);
The options in the km(key mapping) are Element (Value type)/ Component (Inner Object in same table)/ ManyToMany (That i don't really understand in this context)
I Tried using ManyToMany in both because it seems the most logical thing, but it didn't work.
When saving the Dictionary SaveUpdate passed, but it didn't save right to the DB, and couldn't Get the Dictionary back.
Edit: here are sample Dictionary structure
public class Entity1Map : ClassMapping<Entity1>
{
public Entity1Map()
{
Id(x=> x.ID,m=>m.Generator(Generators.Guid));
}
}
public class Entity2Map : ClassMapping<Entity2>
{
public Entity2Map()
{
Id(x=> x.ID,m=>m.Generator(Generators.Guid));
}
}
public class Entity3 { public IDictionary<Entity1,Entity2> Dict { get;set; } }
public class Entity3Map : ClassMapping<Entity3>
{
public Entity3Map()
{
Id(x=> x.ID,m=>m.Generator(Generators.Guid));
//Map Dict??
}
}
as for table structure -
Entity1 Table : ID Column
Entity2 Table : ID Column
Entity3 Table : ID Column
Dict Table : Entity3_ID,Entity1_ID,Entity2_ID
doesn't have to be this table structure if it is saved and recreated from DB in a different one
@Daniel - here is the hbm
<map name="Targets" table="Dict">
<key column="Entity3ID" />
<map-key-many-to-many class="Entity1" column="Entity1ID" />
<many-to-many class="Entity2" column="Entity2ID" />
</map>
Edit 3 (i think) :
var entity3 = new Entity3();
var entity1 = new Entity1();
var entity2= new Entity2();
entity3.Dict[entity1] = entity2;
using (var session = GetSession())
{
session.SaveOrUpdate(entity1);
session.SaveOrUpdate(entity2);
session.SaveOrUpdate(entity3 );
session.Flush();
}