Hi I am writing linq query to get max count with columns from the two tables. I write sql query and it is below.
select MAX(p.dispalyOrder) from NCT_Process p INNER JOIN NCT_Process_Settings s ON
p.projectId =s.projectId AND p.level=s.level
I tried to linq as below.
dbObject = (from c in entityObject.NCT_Process_Settings
join process in entityObject.NCT_Process on c.projectId equals process.projectId
join level in entityObject.NCT_Process on c.level equals level.level
select new settingsobject
{
MAX(p.dispalyOrder) to some propert of settingsobject
}).Tolist();
I am not sure how to get max display order from the process table. Any help would be appreciated. Thank you.
You just select the value and then call
Max
on the query. Also to join on multiple columns you have to create anonymous classes with the columns you want to match.If you have other columns you also want to aggregate then you can do a group by on a constant value.
Note the use of
Single
because an group by on a constant will only result in one row.Or if you just want to get the max display order grouped by another column then do this
Note that the
Key
is whatever you put after theon
and thatgrp
is a collection of the values before theon
. And in this case there can be multiple results so you'd useToList
to run the query.