I think this should be straightforward, but with NHibernate simple things are always the most complicated.
I have two POCOs which reference each other through HasManyToMany:
public class Foo1
{
//other properties
public virtual IList<Foo2> Foo2s {get;set;}
}
public class Foo2
{
//other properties
public virtual IList<Foo1> Foo1s {get;set;}
}
And the mappings:
class Foo1Map : ClassMap<Foo1>
{
//other mappings
HasManyToMany(c => c.Foo2s);
}
class Foo2Map : ClassMap<Foo2>
{
//other mappings
HasManyToMany(c => c.Foo1s);
}
The join table is correctly created, it has 2 fields which are on foreign keys to the respective tables, all fine, the HUGE problem is that those 2 fields should be primary key (or at least unique) while they aren’t. I tried playing around with various fluent methods chained to HasManyToMany but without any result.
How do I get the generated manytomany table to have primary key on the 2 foreign key fields without having to create a custom POCO and map it with composite key?
Thanks.
a unique constraint and also index
Updated: or as a convention for HasMany (code like this i used in a project), not nice but working
i think there is the code in the trunk of FNH to get rid of this hack