On August 30, 2016 7:42:29 AM EDT, Ivan Ruiz de Eguilaz Sosoaga 
<iruizegui...@gmail.com> wrote:
>I have tried to simplify the data model. Creating by my hand the third 
>table, and avoiding to use many to many, so I have define a IList
>element 
>and a mapping hasMany

Remember it may look and feel naturally like a model, but it's still the 
database you are dealing with. Both sides of the now one to many need to be 
saved or updated first. Then you can save the joining entity.

Also assuming you have implemented the repository pattern for your session.

>The idea is to try the following:
>
>One Email has a list of Destiny_Person:
>
>public virtual IList<Destiny_Person> Destiny_Persons {get; set; }
>
>and the mapping:
>mapping.HasMany(x => x.Destiny_Persons ).Inverse().Cascade.All();

HasMany(x => x.Collection)
    .LazyLoad()
    .Inverse()
    .AsBag()
    // That or rely on you identity naming conventions
    .ForeignKeys.Add("ParentId")
    .Cascade.AllDeleteOrphan();

Remember there will be a database backing your model in the form of proxies.

Some people like to instruct the session to access a backing field, but I 
haven't found that to be as necessary, yet. But I reserve the right to change 
my mind, depending on the situation.

You may want a bidirectional list alongside the list property that sets or 
nullifies the parent reference upon adding or removing. You don't always need 
to use that property, but when you do, it hides the bookkeeping of connecting 
both sides to the joining entity.

I also like to initialize my collections to at least an empty list instead of 
null. Then I don't need to worry about any bidirectional null references.

Google StackOverflow; there is usually at least one question for virtually any 
level of question you can think of asking.

>This does not work properly neither because I save the email with a
>couple 
>of elements in the list, the email is saved, the list of elements are
>saved 
>as well but without the foring_key attributte. I see in the log the
>insert 
>of the email and the inserts of the destiny_persons but nhibernate do
>not 
>insert the column email_Id.
>
>:(((

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fluent-nhibernate+unsubscr...@googlegroups.com.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
Visit this group at https://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.

Reply via email to