I need to connect to two objects in five columns, and I need GROUP BY each column in SELECT plus to get COUNT for each GROUP BY group. Although this is a cake to me in SQL, I am hopelessly confused in every example I can find for LINQ.
I found the following two questions ( C # Linq Group By across multiple columns [duplicate] and Group By Multiple Columns ) similar to mine, but I'm still confused about how to do this. Here is my SQL statement:
SELECT o.org_hq_name,
o.org_command_name,
o.org_region_name,
o.org_installation_name,
o.org_site_name,
o.org_subsite_name,
o.org_hq_id,
o.org_command_id,
o.org_region_id,
o.org_installation_id,
o.org_site_id,
count(org_site_id) AS count
FROM organization o, asset a
WHERE o.org_hq_id = hq_org_id
AND o.org_command_id = a.command_org_id
AND o.org_region_id = a.region_org_id
AND o.org_installation_id = a.installation_org_id
AND o.org_site_id = a.site_org_id
GROUP BY o.org_hq_name,
o.org_command_name,
o.org_region_name,
o.org_installation_name,
o.org_site_name,
o.org_subsite_name,
o.org_hq_id,
o.org_command_id,
o.org_region_id,
o.org_installation_id,
o.org_site_id
I have a connection below:
var join1 = from m in context.asset
join o in context.organization
on new {hqID = a.hq_org_id, commandID = a.command_org_id, regionID = a.region_org_id, installationID = a.installation_org_id, siteID = a.site_org_id}
equals new {hqID = o.hq_id, commandID = o.command_id, regionID = o.region_id, installationID = o.installation_id, siteID = o.site_id}
select new
{
hqID = o.hq_id,
commandID = o.command_id,
regionID = o.region_id,
installationID = o.installation_id,
siteID = o.site_id
};
I have a group below:
var group1 = from a in context.asset
group a by new
{
a.hq_org_id,
a.command_org_id,
a.region_org_id,
a.installation_org_id,
a.site_org_id
} into asset
select new
{
}
Please help me with GROUP BY syntax using JOIN in two tables, but in MULTIPLE columns from two tables AND get a counter for each group.