嗨,我在 MVC3 中工作,对于数据库通信,我正在使用 NHIBERNATE
我在更新记录时遇到问题。
首先 session.SaveorUpdate 不起作用然后我尝试了以下操作,但这也不起作用:(
public bool EditParentStudent(ParentStudent parentstudent)
{
log.Debug("Start");
if (parentstudent == null)
{
throw new ArgumentNullException("parentstudent");
}
ISession session = DataAccessLayerHelper.OpenWriterSession();
ITransaction transaction = session.BeginTransaction();
bool saved = false;
try
{
session.SaveOrUpdate(parentstudent);
transaction.Commit();
saved = true;
}
catch (SessionException ex)
{
if (transaction != null && transaction.IsActive)
transaction.Rollback();
log.Error(ex);
}
finally
{
if (transaction != null)
transaction.Dispose();
if (session != null && session.IsConnected)
session.Close();
}
log.Debug("End");
return saved;
}