Thursday, February 18, 2010

Linq2Sql - Group By Count

public List GetTotalRegisteredUserCount()
{
var qry = from aspnet_Profile profile in aspnet_Profiles
group profile by profile.Country into grp
select new {Country = grp.Key,
Count = grp.Select(x => x.Country).Distinct().Count()
};

return qry.ToList();
}

No comments: