<< I'm led to believe that this is because NHibernate wants to do an insert with EmployeeId as NULL and then update it to the ID of the parent, and I have a non-null constraint on employeeID.>> Yes.
<< Or am I going to have to put the Employee reference in employee status?>> Yes. Use a bidirectional ref and mark the collection side with inverse=true and let the child object take care of the ref. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Tony Sent: den 10 februari 2009 10:30 To: nhusers Subject: [nhusers] Uni-directional one-to-many mapping.... Hi, I have a simple scenario within NHibernate that I just can't seem to get my head around at the moment. Basically (and I've distilled this down for the purposes of illustration), I have a one-to-many relationship between entities Employee and EmployeeStatus. Both are simple POCO's, with Employee having properties for ID, Name and an IList of EmployeeStatus entities. EmployeeStatus consists of nothing more than ID and StatusText. What I don't need is any reference to the containing employee object in my status object as the management of status' will be done purely through the employee entity. What I want to be able to do is the following code; Employee e = new Employee(); e.Name = "Tony"; e.StatusList.Add( new EmployeeStatus("Status A") ); e.StatusList.Add( new EmployeeStatus("Status B") ); session.Save(e); And have the employeID column on the status table be populated correctly. I've tried various methods, including creating a one-to-many mapping where inverse is false, cascade set to all-delete-orphan, which all looks like it should work, but it generates an exception about being unable to set the EmployeeId in EmployeeStatus. I'm led to believe that this is because NHibernate wants to do an insert with EmployeeId as NULL and then update it to the ID of the parent, and I have a non- null constraint on employeeID. I guess I'm missing something here, so quite simply - can anyone tell me what the mapping should be to achieve the above? Or am I going to have to put the Employee reference in employee status? Thanks in advance Tony --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
