0% found this document useful (0 votes)
157 views7 pages

13-Using Linq (Language Integrated Query) in Epicor BPMs - GingerHelp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views7 pages

13-Using Linq (Language Integrated Query) in Epicor BPMs - GingerHelp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

5/16/24, 3:47 PM Using Linq (Language Integrated Query) In Epicor BPMs — GingerHelp

[email protected]

U S I N G L I N Q ( L A N G UAG E
I N T E G R AT E D Q U E RY ) I N
EPICOR BPMS
ADAM ELLIS · JUNE 11, 2020

FOR EPICOR ERP: KINETIC, V10, & V9

For many new Epicor developers, one of the first hurdles to get over is
using Linq if they have not used it before. Linq (Language Integrated
Query) is a modern C# technique for querying all of the bits in the
programming world that are not databases.

Consider a complex array, for example, where you want to pull out all of
the values that match certain criteria. If it was a database you’d query it
using SQL language (SELECT * FROM TABLE WHERE X=’123’), but for non-
database objects, it was always much more tedious. So enter Linq which
gives us a query interface for these non-database objects but at the same
time tries to fix some age-old paradoxes in SQL language (like why do I
say what values I want before telling it where I want it from). If you have
an application that is composed of both database and non-database
objects it becomes tedious to have two different query languages - enter
Linq to SQL.

This is where we start off with Epicor as they have very sensibly
standardized on using Linq as the universal query language in BPMs. The
rest of this article is going to focus on table queries within Epicor BPMs

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-linq-in-epicor-bpms 1/7
5/16/24, 3:47 PM Using Linq (Language Integrated Query) In Epicor BPMs — GingerHelp

but the concepts are the same for any sort of objects you may wish to
query.

THE SYNTAX
The first thing to know about Linq is that there are two types of syntax for
it - “Query Syntax” and “Lambda Syntax”. Query syntax will be more
familiar to you if you come from a SQL background and Lambda syntax
will be more familiar if you come from a web programming background.
They both have the same end result - it is purely a matter of preference.

THE QUERY
So let’s start with a really basic Linq query - getting a list of all of the active
employees. Epicor stores employee data in a table named EmpBasic and
there is a field for EmpStatus that is set to ‘A’ if they are active. Here is
what that query looks like:

// Query Syntax
var emps = (from e in Db.EmpBasic
where
e.Company == "EPIC06"
&& e.EmpStatus == "A"
select new { e.EmpID, e.Name } );

// Lambda Syntax
var emps = Db.EmpBasic.Where(e => e.Company == "EPIC06"
&& e.EmpStatus == "A");

So as you can see here, very similar but query syntax is going to look
more like what you’d be used to with a SQL background - with the

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-linq-in-epicor-bpms 2/7
5/16/24, 3:47 PM Using Linq (Language Integrated Query) In Epicor BPMs — GingerHelp

biggest difference being the “SELECT” part is moved to the end. Lambda
comes out a little more condensed.

Now if you want to loop through these results you can just do something
like this:

foreach(var emp in emps) {


string blah = emp.EmpID + ' ' + emp.Name;
}

You will notice here that the columns from the database (EmpID and
Name) are accessible as simple properties as we iterate over the results -
that works for only non UD fields. If you wish to access a UD field you
need to use the square bracket syntax like so:

foreach(var emp in emps) {


string blah = emp.EmpID + " " + emp.Name + " " + emp["
}

How about when you need to query across multiple tables? That is a
situation where I put my preference for Lambda aside as query syntax is
clearly the best choice. Here is an example:

var rows = (from d in Db.OrderDtl


join p in Db.Part on
new {d.Company, d.PartNum} equals
new {p.Company, p.PartNum}
join r in Db.OrderRel on

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-linq-in-epicor-bpms 3/7
5/16/24, 3:47 PM Using Linq (Language Integrated Query) In Epicor BPMs — GingerHelp

new {d.Company, d.OrderNum, d.OrderLine}


new {r.Company, r.OrderNum, r.OrderLine}
join pp in Db.PartPlant on
new {d.Company, d.PartNum} equals
new {pp.Company, pp.PartNum}
where
d.Company == "EPIC06"
&& d.OrderNum == 12345
&& pp.Plant == "MfgSys"
select new { r.Make, p.PartNum, p.ClassID,

Here I am starting with OrderDtl aliased as d. Then I join to Part (aliased


as p) like so:

join p in Db.Part on
new {d.Company, d.PartNum} equals
new {p.Company, p.PartNum}

So the second line is all of the columns to join on from OrderDtl (d) and
the third line is all of the columns to join to in Part (p). This would be the
equivalent of the following in SQL:

FROM
OrderDtl d

LEFT OUTER JOIN Part p ON


p.Company = d.Company
AND p.PartNum = d.PartNum

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-linq-in-epicor-bpms 4/7
5/16/24, 3:47 PM Using Linq (Language Integrated Query) In Epicor BPMs — GingerHelp

We continue down the line pulling in all of the other tables we wish to join
in, apply a where clause, and then finish up by picking our columns on the
select.

CONCLUSION
All of this is really just the tip of the iceberg but hopefully, it gets you
pointed in the right direction. I hope it helps!

LET'S CHAT ABOUT YOUR EPICOR BPM


PROJECT

AUTHOR: Adam Ellis


Adam Ellis is the owner of
GingerHelp. Adam is a lifelong
entrepreneur and has extensive ERP
and mobile software knowledge
through his consulting and
management experience. He has a
passion for exploring innovative ideas
and how they can change the status
quo. Connect with Adam on LinkedIn
to learn more about his involvement
in the ERP space.

FACEBOOK TWI TTER PINTEREST 4 LIKES

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-linq-in-epicor-bpms 5/7
5/16/24, 3:47 PM Using Linq (Language Integrated Query) In Epicor BPMs — GingerHelp

PREVIOUS

EPICOR: HOW TO CALL A BAQ REPORT FROM WITHIN A


CUSTOMIZATION
EPICOR CUSTOMIZATION, EPICOR ERP, EPICOR BAQ

NEXT

EPICOR TIME CLOCK: AUTOMATICALLY CLOCKING EMPLOYEES


OUT AT END OF DAY
EPICOR BPM, EPICOR CUSTOMIZATION, EPICOR ERP

LET’S CHAT!

CONTACT US

GINGERHELP, SERVIC PRODU KNOWLEDGE


LLC ES CTS BASE

8685 Fox Epicor ERP Epicor ERP Epicor ERP Articles


Lake Road Consulting Extensions Infor VISUAL Articles
Sterling, OH P21 ERP Infor Dynamics 365
44276 USA Consulting VISUAL ERP Articles
Infor Extensions Crystal Reports
 VISUAL ERP Articles
[email protected] Consulting SSRS Articles
Dynamics
https://www.gingerhelp.com/knowledgebase-epicor-erp/using-linq-in-epicor-bpms 6/7
5/16/24, 3:47 PM Using Linq (Language Integrated Query) In Epicor BPMs — GingerHelp

365 Bezlio for Mobile


Consulting ERP Articles
SSRS
Developer
Services
Crystal
Reports
Consulting

GingerHelp is an
independent consulting
practice with no direct
© 2019 - 2023 GingerHelp,
affiliation with Epicor® or
LLC
Infor®.

Terms & Conditions |


Epicor®, Vantage®, and Privacy Policy
Prophet 21™ are registered
trademarks of Epicor
Software Corporation®.
Infor® and VIUSAL® are
registered trademarks of
Infor®.
Crystal Reports® is a
registered trademark of SAP
AG.

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-linq-in-epicor-bpms 7/7

You might also like