2012/11/17 Curdin Caspar <[email protected]>:

> And here's the code:
>
> User user = new User() { Name = "UserForTestingCategoryCollection" };
> myUserManager.Save(user);
>
> Category c1 = new Category() { Name = "c1", User = user };
> Category c2 = new Category() { Name = "c2", User = user };
> Category c3 = new Category() { Name = "c3", User = user };
> myCategoryManager.Save(c1);
> myCategoryManager.Save(c2);
> myCategoryManager.Save(c3);
>
> User u = myUserManager.Get(user.DataId);
> Assert.AreEqual(3, u.Categories.Count);

Here, unless you are doing some session management not shown above,
you will be getting back the exact same user instance.
That is Object.ReferenceEquals(user, u) will be true.

So unless the Category constructor updates the User.Categories
collection, it will still be empty. NHibernate won't muck with an
already initalized collection on already loaded instances.

It is you responsibility to update both sides of the bidirectional relationship.


/Oskar

-- 
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