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 4609028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:55:44+00:00 2026-05-22T00:55:44+00:00

I have a list of this object: public class Customer { public int Id

  • 0

I have a list of this object:

public class Customer
{
    public int Id { get; set; }
    public string EmailAddress { get; set; }
    public DateTime ServiceStartDate { get; set; }
    public DateTime? BillingStartDate { get; set; }
    public string Status { get; set; }
}

In preparation for making a chart displayed on a dashboard I am trying to condense this list into another list of this object:

public class DashboardCustomerConversions
{
    public string Month { get; set; }
    public int Trials { get; set; }
    public int Purchased { get; set; }
}

Where the end result looks something like:

Month       Trials   Purchases
---------   ------   ---------
Dec 2010    390      250
Jan 2011    345      190
Feb 2011    576      340

I am having a hard time coming up with a LINQ statement that can achieve the desired end result. This statement is very close:

var list = from b in results
           group b by new { b.ServiceStartDate.Year, b.ServiceStartDate.Month } into g
           select new Test
                      {
                          Month = string.Format("{0} {1}", CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month), g.Key.Year),
                          Trials = g.Count(),
                          Purchased = g.Count()
                      };

The obvious problem in is the “Purchased = g.Count()” line in that it just repeats the Trials result. I would like to count objects where the BillingStartDate.HasValue is true.

Is there a way to restructure the LINQ to make this work?

Edit: I would prefer a fluent style of syntax but I was unable to get the above to work. Answer in any variation would be great.

  • 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-05-22T00:55:44+00:00Added an answer on May 22, 2026 at 12:55 am

    You need to pass a condition to the Count method.

    Purchased = g.Count(q => q.BillingStartDate.HasValue)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class: public class DocumentCompare { public string Customer; public string
I have a wrapped list that looks like this: [Serializable] public class OrderManager :
I have (for example) these two objects: class Customer { public int Id {
I have a list of customer objects (e.x: List customers) public class Customer {
I have some classes like this: public class Customer { } public interface IRepository
I have a wrapped list that looks like this: [JsonObject(MemberSerialization.Fields)] public class OrderManager :
Background I have a list . This list has many objects. Each object has
I have a a method like this : List < Object > getObjects(List<Integer> ids)
I have written a function for deleting object preiodically. function add(variable, expireSecond){ this.list[variable] =
I have two questions, actaully... First off, Why cant I do this: List<Object> object

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.