Thanks José , this sorted it perfectly. Easy when you know how.
From: [email protected] [mailto:[email protected]] On Behalf Of José F. Romaniello Sent: 28 March 2011 11:40 To: [email protected] Subject: Re: [nhusers] composite-element and Id generator I think you should use <idbag instead of <bag: http://nhforge.org/doc/nh/en/index.html#collections-idbag 2011/3/28 Richard Wilde <[email protected]> I am trying to work out how to save a unidirectional parent/child association, I have the following bag defined <bag name="ActorList" table="ActorRole"> <key column="MovieId" /> <composite-element class="Actor"> <property name="Name"/> </composite-element> </bag> When I try and use the following code to save a movie and a list of actors then var movie = new Movie { Name = "Movie Name", ActorList = new List<Actor> { new Actor { Name = "Rippo"}, new Actor { Name = "Ryan"} } }; ... Session.Save(movie); . . . The following SQL code is generated, note MovieId is the foreign key and Id will be my Primary key on the table INSERT INTO ActorRole(MovieId, Name) VALUES('4a833388-9946-4ed9-8e83-9eb400b841e0','Rippo') However I would like NHibernate to add in my primary key Id automatically. Therefore I added the property <composite-element class="Actor"> <property name="Name"/> <property name="Id"/> </composite-element> And the following SQL is now generated:- INSERT INTO ActorRole (MovieId, Name, Id) VALUES '4a833388-9946-4ed9-8e83-9eb400b841e0','Rippo', '00000000-0000-0000-0000-000000000000') As you can see the Primary key is all zero’s, how can I tell NHibernate to generate the Guid for me? Is this possible? Thanks, Rippo -- 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] <mailto:nhusers%[email protected]> . For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- 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. -- 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.
