Reputation: 41
How to a count of some product by grouping them and the names of products too using MVC?
The following query I made, but after that I don't know what to do.
var qrystr = new StringBuilder();
qrystr.Append("select SelectedPersonId, count(PersonName) as CountData from [dbo].[EntryMaster] Group by SelectedPersonId");
I need to show the SelectedPersonId
, and the CountData
...
How can I solve this through MVC?
Upvotes: 0
Views: 154
Reputation: 35212
If you're using entity framework, you can use linq
to query your data set:
context.EntryMaster
.GroupBy(e => e.SelectedPersonId)
.Select(g => new { SelectedPersonId = g.Key, CountData = g.Count() })
.ToList()
This returns a List
of objects with 2 properties: SelectedPersonId
and CountData
Upvotes: 2
Reputation: 136
Cant you just add .Count() at the end of the qrystr.Append()
?
Upvotes: 0