Epicor Kinetic 2026.100.x C# Issue

Hi all,

I’m trying to run some simple C# using a Data Directive BPM Custom Code Block on the ShipHead table which is failing.

foreach (var ShipHead in (from ShipHeadRow in Db.ShipHead

where ShipHeadRow.Company == Session.CompanyID

&& ShipHeadRow.PackNum == ps

select ShipHeadRow))

{}

This should fire when the ShipHead.ReadyToInvoice field changes from False to True. But it just throws an error.

The code compiles fine.

Thanks,

James

put a try catch around it and send the error to the screen via a message box. May help you diagnose the issue

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

Since your query filter is on the primary key of the table, it would be better to write it like this:

var shipHead = Erp.Tables.ShipHead.FindFirstByPrimaryKey(Db, Session.CompanyID, ps);
if (shipHead != null)
{
   // do stuff
}

Since the query will return at most a single row, there’s no need to put it in a loop.

You learn something new everyday :party_parrot:

This resolved our issue.

Thank you!

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.