AwonDanag AwonDanag - 1 year ago 83 Question

Simple SQL Count to LINQ?

I've spent the last two hours or so researching this. Is new to LINQ btw.
How do I get an SQL like this to a LINQ query?

SELECT, name, designation, COUNT(
FROM region r
LEFT JOIN area a on a.region_id =
GROUP BY, name, designation

My alternative of course is to place this in a
(which I can figure out) but I'd like this to be added to my knowledge. Thanks!

P.S. Either VB or C# will do but I'd prefer the former.

Answer Source

I think it would be like this:

var result =
            from r in regions
            join a in areas on equals a.region_id into subvalues
            from _ in subvalues.DefaultIfEmpty()
            select new { id =, name =, designation = r.designation, count = subvalues.Count() };
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download