Grouping with Data Entities
I am really loving the data entity in my new projects but have come across a couple of issues already. Tonight I learned about using a field that is not a part of your database and not in the entity but is a consolidation field from a group. Once I found some good samples it worked incredibly well and I had a little summary grid on the page in just a couple of minutes. So here is what I did
using (myEntityName context = new myEntityName())
{
//First I declared a couple of variables because I was looking at data between specific dates
DateTime startdate = DateTime.Parse("2014-02-01");
DateTime enddate = DateTime.Parse("2014-02-01");
var dbRecords = (from c in context.myTableName
where (c.MemberStartDate >= startdate && c.MemberStartDate <= enddate)
group c by c.Concept into g
//So you notice I used a g for the group by set of data
//The g.key part threw me for a second but then I realized it equates to the field you are grouping by
select new
{
Concept = g.Key,
New_Customers_Count= g.Count()
}).ToList();
WebDataCustCount.DataSource = dbRecords;
WebDataCustCount.DataBind();
using (myEntityName context = new myEntityName())
{
//First I declared a couple of variables because I was looking at data between specific dates
DateTime startdate = DateTime.Parse("2014-02-01");
DateTime enddate = DateTime.Parse("2014-02-01");
var dbRecords = (from c in context.myTableName
where (c.MemberStartDate >= startdate && c.MemberStartDate <= enddate)
group c by c.Concept into g
//So you notice I used a g for the group by set of data
//The g.key part threw me for a second but then I realized it equates to the field you are grouping by
select new
{
Concept = g.Key,
New_Customers_Count= g.Count()
}).ToList();
WebDataCustCount.DataSource = dbRecords;
WebDataCustCount.DataBind();
Comments