Simple linq statement throws error

Why is below code throwing error? It is the ‘to’ of a BPM Set Argument/Variable Setter.

Erp.Tables.JobOper;
(from OpComplete in JobOper
where JobOper.JobNum == CallContextBpmData.Character01
&& JobOper.AssemblySeq == CallContextBpmData.Number01
select OpComplete
)

ERROR: Expression should contain only one statement

You can only have one statement in the set argument blocks, otherwise you get the error shown. Erp.Tables.JobOper; is your first statement, the rest is the second. If you need more than one statement, you can set your variable in a custom code block instead.

Try something along the lines of:

Db.QuoteHed.Where( r =>r.Company == MyCompany && r.QuoteNum == QuoteToFind).Select( r =>r.MyUDField_c ).DefaultIfEmpty("Not Found").FirstOrDefault();

Obviously adjust for your table and conditions, and type. The .DefaultIfEmpty("Not Found") part is optional. Use it to return a specific value if no records matched the conditions.

I changed to the style suggested, same error, changed the variables and still get same error

Db.JobOper.Where( r =>r.Company == MyCompany && r.JobNum == JobNo && r.JobOper.AssemblySeq == AssemblyNo).
Select( r => r.OpComplete ).FirstOrDefault();

Remove the “;” from the end of the statement.

Db.QuoteHed.Where( r =>r.Company == MyCompany && r.QuoteNum == QuoteToFind).Select( r =>r.MyUDField_c ).DefaultIfEmpty("Not Found").FirstOrDefault()
1 Like

Well sheesh. I have not only to learn Epicor, I have to learn C#. Thank you for your help! It is working now.

My bad for not stripping off the ;

The code I copied it from (a @josecgomez post) was to set a variable:

string MyData = Db.QuoteHed.Where( r =>r.Company == MyCompany && r.QuoteNum == QuoteToFind).Select( r =>r.MyUDField_c ).DefaultIfEmpty("Not Found").FirstOrDefault();
1 Like