A few things that cross my mind:
1. You'll definitely need an appropriate Cascade style for the "HasMany" mapping on ShoppingLists.Items, e.g. SaveUpdate - not sure which mapping system you're using, so don't know the exact syntax
2. 99% of the time, this mapping should be 'Inverse'
3. It looks as you're manually assiging a new ID to the new 'ShoppingListItems' object, which I suspect is causing NH to believe that the new object is persistent.
My general pattern for this sort of thing is as follows (pseudo-code for interesting bits only):
class ShoppingList {
Guid Id { get; protected set; }
ISet<ShoppingListItem> Items { get; protected set; }
public ShoppingList() {
this.Items = new …
}
}
class ShoppingListLine {
Guid Id { get; protected set; }
public ShoppingList List { get; protected set; }
ShoppingListLine(ShoppingList list) {
this.List = list;
this.List.Items.Add(this);
}
void Delete() {
if(this.List != null) this.List.Items.Remove(this);
this.List = null;
}
}
var dbList = ….;
var newItem = new ShoppingListLine(dbList); // ctor handles association maintenance
/Pete
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.