Hi Ramon

I think due to my inexperience with NHibernate the mapping I gave in my 
first example is pretty much wrong.

In principle I would like to having the following mapping

Host -> Sequence (Host.Sequence) [one-to-one]   : host.sequence points to 
one sequence.
Sequence -> Host (Host.Sequences) [one-to-one] : sequence.host points to 
one host.

So that when I set host.sequence = null the sequence is deleted. Note, host 
and sequence are held in separate tables.

As I haven't been able to get this working I have ended up using the 
collection approach as you outlined. 

It would be nice if I could get the one-to-one approach working though :-)

Thanks
Michael

On Wednesday, 2 May 2012 14:22:36 UTC+1, Ramon Smits wrote:
>
>
> I am trying to understand your model
>
> You have two relations from host to sequence:
>
> Host -> Sequence (Host.Sequence) [many-to-one]
> Sequence -> Host (Host.Sequences) [
>
>
> 1. I expect it to work correctly when you remove the property and mapping 
> for Host.Sequence.
>
> 2. Your problem seems that you have multiple properties sharing the same 
> child entity Sequence.
>
> What is your requirement for this model as it seemes a bit flawed for an 
> aggregate?
>
> I have created a similar model once but there the child entity was not 
> part of the aggrete. There I had this:
>
> Language
> Document.Languages
> Document.DefaultLanguage
>
> This required the language entity to be managed apart from the document. 
> My guess is that you are in the same situation.
>
>
> Would the following work?
>
> var host = new Host();
> var sequence = new Sequence();
>
> host.Sequence = sequence;
> host.SequencesAdd(sequence);
>
> session.Save(sequence);
> session.Save(host);
>
>
> var host = session.Get<Host>(id);
> var sequence = host.Sequence;
> host.SequenceRemove();
> host.Sequence = null;
>
> session.Delete(sequence);
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/9k-_2bBBT44J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to