This may not be your actual error, but one thing I’d avoid is looping directly over an open Db query.
Run the LINQ query first, materialize it with .ToList(), then loop over the results:
var shipHeads = (
from shipHeadRow in Db.ShipHead
where shipHeadRow.Company == Session.CompanyID
&& shipHeadRow.PackNum == ps
select shipHeadRow
).ToList();
foreach (var shipHead in shipHeads)
{
// your logic here
}
Looping directly over the query keeps the data reader open while your code runs inside the loop. In a BPM, especially on a table like ShipHead, that can hold locks longer than you expect and cause blocking or weird update behavior. Materializing the results first keeps the database read short, then your loop works against the in-memory list.
As a matter of practice NEVER loop on a Db data reader
Just wanted to add that after the entity framework update to our pilot system, most of the fixes to our failing BPMs were solved by doing what @josecgomez has described here.
Our previous code was written without the .ToList() which caused dashboards to break.