Hi, I am currently working on a project that uses NH, FluentNH and Linq2NH. Everything works just fine but I wonder if there is any possibility to improve saving complex object's. I feel that saving objects as it is listed below is not the best practice and cause some performance issues:
Code:
public override void SaveChanges(Member entity)
{
SessionProvider.GlobalSession.Evict(entity);
using (ISession session = SessionProvider.SessionFactory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
foreach (var charge in entity.Charges)
session.SaveOrUpdate(charge);
foreach (var invoice in entity.Invoices)
session.SaveOrUpdate(invoice);
session.Update(entity.ContactInformation);
session.Update(entity.MemberData);
session.Merge(entity);
transaction.Commit();
}
}
SessionProvider.GlobalSession.Update(entity);
}
Please tell me if there is any way of mapping that could cause the member object to be fully saved like this:
Code:
public virtual void SaveChanges(T entity)
{
SessionProvider.GlobalSession.Evict(entity);
using (ISession session = SessionProvider.SessionFactory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
session.Update(entity);
transaction.Commit();
}
SessionProvider.GlobalSession.Update(entity);
}
I intentionally do not show mappings, relations etc. just want to know if it is common for NH to save objects like in first code block.
And regardless of the first answer - how to optimize that ;-)
Regards,