ISession Extension for Saving Multiple Objects
Tuesday, August 26th, 2008Incredibly simple, but quite useful:
public static void Save(this ISession session, params object [] entities)
{
foreach (var o in entities)
{
session.Save(o);
}
}
You can use it like:
session.Save(a,b,c,d,....);
with a list of objects of any type. Useful for unit testing where you want to save multiple items at once.
[Update]
Probably should call it something other than Save, such as SaveAll or SaveList because if you only pass two items to the overload it calls the standard Save(object, int id) version. :(
