NHibernate : Root collection with an root object
- by Daniel
Hi,
I want to track a list of root objects which are not contained by any element. I want the following pseudo code to work:
IList<FavoriteItem> list = session.Linq<FavoriteItem>().ToList();
list.Add(item1);
list.Add(item2);
list.Remove(item3);
list.Remove(item4);
var item5 = list.First(i => i.Name = "Foo");
item5.Name = "Bar";
session.Save(list);
This should automatically insert item1 and item2, delete item3 and item3 and update item5 (i.e. I don't want to call sesssion.SaveOrUpdate() for all items separately.
Is it possible to define a pseudo entity that is not associated with a table? For example I want to define the class Favorites and map 2 collection properties of it and than I want to write code like this:
var favs = session.Linq<Favorites>();
favs.FavoriteColors.Add(new FavoriteColor(...));
favs.FavoriteMovies.Add(new FavoriteMovie(...));
session.SaveOrUpdate(favs);
FavoriteColors and FavoriteMovies are the only properties of the Favorites class and are of type IList and IList. I do only want to persist the these two collection properties but not the Favorites class.
Any help is much appreciated.