我在使用交易的SQLite中发现了一个奇怪的错误,我无法弄清楚.... 下面有我的代码:
_connection.RunInTransaction(() =>
{
_connection.UpdateAll(objProposte);
foreach (Proposte objProposta in objProposte)
{
string propostaID = objProposta.PropostaID;
List<ProposteDetails> lstProdDet = _connection.Table<ProposteDetails>().Where(x => x.PropostaID == propostaID).ToList();
if (lstProdDet != null && lstProdDet.Count() > 0)
{
//AN UPDATE GIVE ME THE SAME ERROR
_connection.DeleteAll(lstProdDet);
_connection.InsertAll(lstProdDet);
}
}
});
似乎是_connection.UpdateAll(objProposte);工作正常,但当我尝试在同一个事务中做其他事情时,我得到以下异常:
System.ArgumentException:savePoint无效,应该是 调用SaveTransactionPoint的结果。参数名称:savePoint
在SQLite.Net.SQLiteConnection.DoSavePointExecute(System.String savePoint,System.String cmd)[0x00063] in &lt; 8f2bb39aeff94a30a8628064be9c7efe&gt;:0 at SQLite.Net.SQLiteConnection.Release(System.String savepoint) [0x00000]在&lt; 8f2bb39aeff94a30a8628064be9c7efe&gt;中:0 at SQLite.Net.SQLiteConnection.RunInTransaction(System.Action动作) [0x0001d]在&lt; 8f2bb39aeff94a30a8628064be9c7efe&gt;中:0 at SQLite.Net.SQLiteConnection.InsertAll(System.Collections.IEnumerable 对象,System.Boolean runInTransaction)[0x0001e] in &LT; 8f2bb39aeff94a30a8628064be9c7efe&GT;:0
在互联网上阅读似乎与嵌套交易有关,但不是我的情况,因为所有这些都是在同一交易中完成的。
谢谢, L -
编辑 28-05-2018 12:16:该配置有效....但应该做同样的事情:(
string my_transaction_point = null;
try
{
my_transaction_point = _connection.SaveTransactionPoint();
_connection.UpdateAll(objProposte, runInTransaction: false);
foreach (Proposte objProposta in objProposte)
{
string propostaID = objProposta.PropostaID;
List<ProposteDetails> lstProdDet = _connection.Table<ProposteDetails>().Where(x => x.PropostaID == propostaID).ToList();
if (lstProdDet != null && lstProdDet.Count() > 0)
{
_connection.DeleteAll(lstProdDet);
_connection.InsertAll(lstProdDet, runInTransaction: false);
}
}
_connection.Commit();
}
catch (Exception ex)
{
_connection.RollbackTo(my_transaction_point);
throw new Exception("UpdateProposta, " + ex.Message, ex);
}
答案 0 :(得分:1)
.UpdateAll
在自己的事务中运行,您可以通过覆盖默认为true
的第二个参数来关闭它:
_connection.RunInTransaction(() =>
{
_connection.UpdateAll(objProposte, false);
// perform the rest of your CRUD operations
~~~
~~~
});