I have what seems to be a very simple question but I can't seem to figure it out. If I have a one to many relationship between [Member] and [Mail]
If I take off inverse it all works, it's just when I call instance.inverse that it doesnt save.
Code:
public class Mail : Entity
{
[Cascade(Enums.CascadeOptions.All)]
public virtual Member Receiver
{
get; set;
}
public virtual string Subject
{
get;
set;
}
public virtual string Body
{
get; set;
}
}
Code:
public class Member : Entity
{
public Member()
{
Mail = new List<Mail>();
}
[Cascade(Enums.CascadeOptions.All)]
public virtual IList<Mail> Mail
{
get; set;
}
}
Inverse is true on a one to many (through an automapping convention)
Code:
public class HasManyConvention : IHasManyConvention
{
public void Apply(FluentNHibernate.Conventions.Instances.IOneToManyCollectionInstance instance)
{
instance.Key.Column(instance.EntityType.Name + "ID");
instance.Inverse();
}}
I try to add a mail item to a member through:
Code:
mail.Receiver = receiver;
receiver.Mail.Add(mail);
_repository.SaveOrUpdate(mail);
FlushSessionAndEvict(mail);
The cascade attribute is something I created to tell the automapper to cascade and it works. I also just set the cascade to all for this test no matter what the attribue is.
Now what's weird is the mail item is saved to the database, there is a foreign key called 'MemberId' which SHOULD have the foreign key to the parent member table and a column called ReceiverFk which is according to my convention but shouldn't be there if there is already a foreign key relationship with MemberId. When I retrieve the user it doesn't have the mail item attached to it. If I take off inverse everything works, the foregin key is saved in MemberId.
I don't want to take off inverse though because it entails another update call to the database. What can I do?
I can supply the maps the automapper generated.
Thanks