views:

377

answers:

1

Hi. I want to create a many to many relationship, but I want to have in the new table(MessageReceivers) a unique contraint on both columns (AdvanceMessageId,UserId):

mapping.HasManyToMany(x => x.Receivers) .WithParentKeyColumn("AdvanceMessageId") .WithChildKeyColumn("UserId") .Cascade.All() .LazyLoad() .WithTableName("MessageReceivers");

Thanks for help

A: 

You should also map the inverse side of the relationship like

mapping.HasManyToMany(x => x.Users).WithTableName("MessageReceivers") .WithParentKeyColumn("UserId") .WithChildKeyColumn("AdvanceMessageId").Inverse() ;

In neverst Fluent NHibernate you will have to change

  • WithTableName -> Table

  • WithParentKeyColumn -> ParentKeyColumn

  • WithChildKeyColumn -> ChildKeyColumn

Spikolynn