NHibernate session.Flush() 不起作用也没有报错
NHibernate session.Flush() doesn't work and no error report
当我使用 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;
}
而不是 Session.Flush() 尝试使用事务:
using (var transaction = session.BeginTransaction())
{
transaction.Commit();
}
呃,问题是有些字符串超出了数据库类型的限制长度。
但是,我很困惑为什么 VS 无法捕获错误并且似乎从未发生过?
当我使用 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;
}
而不是 Session.Flush() 尝试使用事务:
using (var transaction = session.BeginTransaction())
{
transaction.Commit();
}
呃,问题是有些字符串超出了数据库类型的限制长度。 但是,我很困惑为什么 VS 无法捕获错误并且似乎从未发生过?