Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:22:57+00:00 2026-06-06T19:22:57+00:00

I have following Table with records for ActivityLog: ID, UserId, Category, Created 1 11

  • 0

I have following Table with records for ActivityLog:

ID, UserId,      Category,   Created
1       11     DeAssigned    05/10/2012
2       11          LogIn    05/11/2012
3       20       Assigned    06/15/2012
4       11       Assigned    06/10/2012
5       20     DeAssigned    06/13/2012
6       20       Assigned    07/12/2012
7       11     DeAssigned    07/16/2012
8       20       Assigned    08/15/2012
...

now i want to query the Table to create same struct the same Result such as this:

var data = new[] { 
                    new { Month = "05", Assigned = 14, DeAssigned = 5, LogIn=1 },
                    new { Month = "06", Assigned = 5, DeAssigned = 2, LogIn=0 },
                    new { Month = "07", Assigned = 50, DeAssigned = 8, LogIn=0 },
                    new { Month = "08", Assigned = 15, DeAssigned = 1, LogIn=0 }
};

what i have achieved:

var result = (from l in repoA.GetAll()
                      where   l.Created >= System.DateTime.Now.AddYears(-1)
                      group l by new { l.Created.Value.Month, l.Category }
                      into groups
                      orderby  groups.Key.Month 
                      select new
                                 {
                                     Month = groups.Key.Month,
                                     Category = groups.Key.Category,
                                     Count = groups.Count()
                                 });

there is not optimal result but count all Activity’s grouped by Month:

 [0] {Month = 6, Category = Assigned, Count = 2}
 [0] {Month = 6, Category = Designed, Count = 1}
 [0] {Month = 6, Category = LogIn, Count = 1}
 [0] {Month = 7, Category = Assigned, Count = 3}

How can i query my Table to Format my Result in “Horizontal Counted” format?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:22:58+00:00Added an answer on June 6, 2026 at 7:22 pm

    Or simplier:

    var result = (from l in repoA.GetAll()
                               where   l.Created >= System.DateTime.Now.AddYears(-1) 
                               group l by l.Created.Month into groups
                               orderby groups.Key ascending
                               select new
                                  {
                                      Month = groups.Key,
                                      Assigned = groups.Where(g => g.Category == "Assigned").Count(),
                                      Deassigned = groups.Where(g => g.Category == "DeAssigned").Count(),
                                      LogIn = groups.Where(g => g.Category == "LogIn").Count()
                                  });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simply I have the following table with records , i want to return randomly
I have the following table. When i try to insert records using LINQ to
I have table with following structure and records. table t1 +------+-------------+---------------------+ | name |
I have table with following structure and test records: +--------+--------+---------+ | vid | number
Imagine I have following table: NAME DATE OTHER_CONTANT 'A' '2012-06-05' 'baz' 'A' '2012-06-04' 'bar'
I have the following table which records a value per day. The problem is
I have the following table: Id INT/PK UserId INT/FK CreatedDate DATETIME ActivityMarker INT/FK The
I have the following table that records when a particular room in a hotel
--I have a Table named CLASS with the Following Records in it (PK) ClassID
I have the following table of records: Product | Colour | Quantity --------------------------------------- Product

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.