Linq to SQL retrieves individual records grouped by date

I am trying to get a list of individual “customer type identifier” entries for each every 24-hour period and add them to the list.

Say my data structure is like

DATE        TYPEOF CUSTOMER    CUSTOMER TYPE ID
31-10-2013  GUEST              3
31-10-2013  REGISTERED         4
31-10-2013  MANAGER            2
30-10-2013  GUEST              3
30-10-2013  REGISTERED         4
30-10-2013  MANAGER            3

In linq to sql, I want to get all the records for every day (24-hour period), then get a distinct amount of each "client type identifier"

I started, but I don’t know how to act. How can i do this?

var results = _customerTable.GroupBy(c => new {Date = c.Date.Date}).....
+4
source share
1 answer

you can try the following code example:

var results = _customerTable.GroupBy(c => new {c.Date, c.CUSTOMER_TYPE_ID}).Select(g => new {g.Key.Date, g.Key.CUSTOMER_TYPE_ID, MyCount = g.Count()});

using this method, you can get the number of records for Dateand CUSTOMER_TYPE_ID.

+1
source

Source: https://habr.com/ru/post/1689620/


All Articles