Hi,

I have set up a standard one to many relation ship between two
entities:

Functionality <--> FunctionalityGroup

It is mapped in a way that Functionality has a Many-to-One side with
FunctionalityGroup, while FunctionalityGroup has a One-to-Many with
Functionality.

My requirements are that when creating a new functionality I assign it
its functionalitygroup and when showing the report of functionalities
within a group that I can get the group, load its children
(functionalities) and show it.

This model supports it just fine, however when creating a new
functionality I am having a small issue...

In normal situations and all the text book samples it is done like the
following:

var functionalityGroup = groupRepo.Load(1);
var functionality = new Functionality;

functionality.Group = functionalityGroup;
functionalityGroup.Funcitonalities.Add(functionality);

funcRepo.Save(functionality);


This works perfectly so my next step is to move this assignment logic
on its own:

var functionalityGroup = groupRepo.Load(1);
var functionality = new Functionality;

functionality.Group = functionalityGroup;

funcRepo.Save(functionality);


where Group property setter (it might as well be SetGroup method or
something) is:

_group = value;
_group.Funcitonalities.Add(this);


This brakes with an error like NHibernate.LazyInitializationException
- Illegal access to collection.


If I turn this around, and move this logic to the Parent in this
situation - the FunctionalityGroup, it gets a method AddFunctionality:

functionality.Group = this;
this.Funcitonalities.Add(functionality);


>From the other side, this works perfectly...probably because we are
doing it on the Parent itself.

Now, my question is...is there any way to get it to work in my case
from above where I get Lazy exception?
I consider this not to be a standard practice, but more an exception
in the usage, but still for this case a needed one...


Thanks,
Vladan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
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