Malcolm,
I know it is off topic. But if this is a real project it may be worth looking at your design and making it a uni-directional association. The model as shown below means an ingredient can only be used in one recipe ;) From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of Hudson Akridge Sent: 15 April 2009 16:20 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Updating collection gives null id error Ah, good point. Yes. If you've got the collection side mapped as Inverse, it's the many side (ingredient side) that is going to be doing the save for maintaining the associations. This means you will need to be doing a bi-directional association in your domain model. That's why it's imperative as well to make sure that the many side has cascade set to save-update at the minimum in your scenario. On Wed, Apr 15, 2009 at 8:48 AM, Greg Cook <greg.co...@gmail.com> wrote: When you added the ingredient to the Ingredients collection, did you also assign the Recipe to the Ingredient? You need to make sure both sides of the bi-directional association are updated before saving... Hope this helps On Wed, Apr 15, 2009 at 7:28 AM, MalcolmS <malcolm...@gmail.com> wrote: Hi, When I add an ingredient to Ingredients collection and do save or update I get and exception RecipeID cannot be null for Ingredients What do I add to the mapping to fill in the foreign key RecipeID in Ingredients??? Thanks This is the mapping files. public class IngredientMap : ClassMap<Ingredient> { public IngredientMap() { WithTable("Ingredients"); Id(x => x.IngredientID).GeneratedBy.Identity(); Map(x => x.IngredientName); Map(x => x.Units); Map(x => x.Measure); Map(x => x.ModifiedOn); References(x => x.Recipe).ColumnName ("RecipeID"); } } public class RecipeMap : ClassMap<Recipe> { public RecipeMap() { WithTable("Recipes"); Id(x => x.RecipeID).GeneratedBy.Identity(); Map(x => x.RecipeTitle); Map(x => x.PrepTime); Map(x => x.CookTime); Map(x => x.Method); Map(x => x.Rating); //Map(x => x.EnteredByID); Map(x => x.ModifiedOn); Map(x => x.Completed); References<User>(x => x.User).ColumnName("EnteredByID"); HasMany<Ingredient>(x => x.Ingredients) .KeyColumnNames.Add("RecipeID") .Inverse() .Cascade.All().AsBag(); HasMany<Comment>(x => x.Comments) .KeyColumnNames.Add("RecipeID") .Inverse() .Cascade.All().AsBag(); HasMany<RecipeImage>(x => x.Images) .KeyColumnNames.Add("RecipeID") .Inverse() .Cascade.All().AsBag(); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---