当我使用NHibernate来更新或保存(插入)实体时,我发现代码(session.Flush())没有工作且没有错误信息,程序在那里结束(不是故障,功能在那里结束)。 但我成功使用它插入实体,我没有修改任何代码。 我很困惑,请帮助我。 代码在那里:
ISession session = SessionBuilder.SessionFactory.OpenSession();
switch (editType)
{
case 'S': {
try
{
//new info set default;
cs.ID = 132;
clc.ID = cs.ID;
cmc.ID = cs.ID;
cs.COEFFICIENT_ID = 0;
cs.IF_ASSOCIATION = 'N';
cs.COST_PRICE = 0.0f;
session.Save(cs);
session.Save(clc);
session.Save(cmc);
session.Flush();//<<--if i set a breakpoint in there,
//and next step the whole function will end,no catch no finally
//no return,the application seem never run this function.
//and the application continues to run normal.
flg = true;
}catch (Exception e)
{
flg = false;
throw e;
}
finally
{
session.Close();
}
break;
}
case 'E': {
try
{
session.Update(cs);
session.Update(clc);
session.Update(cmc);
session.Flush();//<<--if i set a breakpoint in there,
//and next step the whole function will end,no catch no finally
//no return,the application seem never run this function.
//and the application continues to run normal.
flg = true;
}catch(Exception e)
{
flg = false;
throw e;
}
finally
{
session.Close();
}
break; }
default: { return false; }
}
return flg;
}
答案 0 :(得分:0)
而不是Session.Flush()尝试使用事务:
using (var transaction = session.BeginTransaction())
{
transaction.Commit();
}
答案 1 :(得分:0)