I’m converting some ABL code to custom C# code. In one particular piece of code, the code is deleting any matching VendPBrk records:
foreach (var ttPart_xRow in ttPart)
{
// do some other stuff first...
// field initializations go here...
// ....
foreach (var VendPBrk_iterator in (from VendPBrk_Row in Db.VendPBrk
where string.Compare(VendPBrk_Row.Company, ttPart_xRow.Company, true) == 0
&& string.Compare(VendPBrk_Row.PartNum, ttPart_xRow.PartNum, true) == 0
select VendPBrk_Row))
{
VendPBrk = VendPBrk_iterator;
if (VendPBrk != null)
{
Db.VendPBrk.Delete(VendPBrk);
}
}
}
However, when this code runs, I get an exception: New transaction is not allowed because there are other threads running in the session.
In another thread I found the suggestion to make the code run asynchronously instead of synchronously. This makes the exception go away, however, the field initializations in the rest of the code no longer work.