NHibernate : Root collection with an root object

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2010-05-26T16:20:36Z Indexed on 2010/05/26 16:21 UTC
Read the original article Hit count: 210

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.

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about collections