Automatic collections

Mar 9, 2015 at 8:58 PM
If i have a parent entity and use the

parent.childs.Add(chield) / the child.parent property is not set, and the same with .Remove(child)

so when ai save the changes it saves all chields that where added and removed.

This is the way that entityframework works, and is very anoying, nhibernate does this correctly, is it possible that VITA can do it the same way (I think the correct way :) )

Regards
Coordinator
Mar 9, 2015 at 9:12 PM
For both one2many and many2many, adding entities to child list does NOT do anything to child.Parent ref. You normally do it explicitly. For many2many (book.Authors), adding an author to book.Authors creates link record with proper references, but that's it. No more auto actions; after you save, the child list will be refreshed automatically and you will see new child in list even if you did not add it explicitly. In this sense, child list for one-to-many is more like ICollection (that does not allow add/remove). I think this is more predictable way of doing things; I recommend creating extension methods that work as constructors, and all parent(s) should be listed in parameters and set in extension method explicitly. I did not see any problem using this pattern, works pretty well.
Mar 9, 2015 at 9:39 PM
Quote:
after you save, the child list will be refreshed automatically and you will see new child in list even if you did not add it explicitly. In this sense, child list for one-to-many is more like ICollection (that does not allow add/remove). I think this is more predictable way of doing things;

I have tried and this does not refresh the child list automaticaly.

Regards
Coordinator
Mar 9, 2015 at 9:42 PM
I will look into this, thanks! looks like some code got lost in refactorings...
Coordinator
Mar 16, 2015 at 4:36 PM
Edited Mar 16, 2015 at 6:27 PM
Should be fixed now. After SaveChanges all collections (that MIGHT have changed) will be refreshed automatically