after some digging, i've uncovered the ISession.Replicate method. however, it's a little more complicated. as you can't use lazy instantiate you need to create your source session factory with something like:
Code:
NH.Cfg.Configuration config = new NH.Cfg.Configuration();
config.Configure();
foreach (NH.Mapping.PersistentClass c in config.ClassMappings)
if (c.IsLazy)
c.IsLazy = false;
foreach (NH.Mapping.Collection c in config.CollectionMappings)
if (c.IsLazy)
c.IsLazy = false;
also, as you'll want to preserve your primary keys you'll need to create your destination session factory with something like (you might want to regenerate your schema as well):
Code:
config = new NH.Cfg.Configuration();
config.Configure(HttpContext.Current.Server.MapPath("~/Config/nh-replication.config"));
foreach (NH.Mapping.PersistentClass c in config.ClassMappings)
if (c.Identifier.IdentifierGeneratorStrategy.Equals("native"))
c.Identifier.IdentifierGeneratorStrategy = "assigned";
destSessionFactory = config.BuildSessionFactory();
then you can have:
Code:
object item;
using (NH.ISession session = sourceSessionFactory.OpenSession())
{
//get item
}
using (NH.ISession session = destSessionFactory.OpenSession())
{
session.Replicate(item, NH.ReplicationMode.Overwrite);
session.Flush();
}
havn't totally tested this yet, but it's on the right track.