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

  • SEARCH
  • Home
  • 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 3846676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:26:03+00:00 2026-05-19T16:26:03+00:00

I have the following query that returns the login count per day from a

  • 0

I have the following query that returns the login count per day from a given date.

var sot =   from uts in DataContext.UserTrackingStatistics
              let startDate = new DateTime(2009, 10, 01) 
              where uts.LastLogin >= startDate
              group uts by uts.LastLogin.Date into myGroup
              orderby myGroup.Key.Date
              select new { Count = myGroup.Count() , myGroup.Key.Date};

I would like this to say the count was 0 for a given day rather than not return anything. How could I do that within this query?

  • 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-19T16:26:04+00:00Added an answer on May 19, 2026 at 4:26 pm

    You can’t do it just with LINQ-to-SQL, as you’d have to use a union on your query with data that doesn’t actually exist, which LINQ-to-SQL can’t do.

    To do this, you’ll need to fill in the gaps client-side. I’m not in front of VS at the moment, but a general approach would be this:

    1. Define your date range (since you mention no end date in your code and we’re talking about login date, I’m assuming that the end date would be the current date.
    2. Use Enumerable.Range to create a list of numbers ranging from 0 to the number of days within your date range, then use Select to transform that list into a list of dates. Select your results using an anonymous type and use the same properties as your L2S statement; this way, the compiler will reuse the same type
    3. Combine your lists together using an outer join (not the most obvious syntax in LINQ, unfortunately) on the Date property
    4. Order your results by date

    This will now show 0 for the gaps.

    I’ll try to post a code sample below, but note that I can’t compile where I am, so it may require tweaking.

    var allDates = Enumerable.Range(0, (DateTime.Today - startDate).TotalDays)
                  .Select(i => new { Count = 0, Date = startDate.AddDays(i) });
    
    var fullResults = from d in allDates
                      join r in results on d.Date == r.Date
                      from oj in r.DefaultIfEmpty()
                      select new { Count = oj == null ? 0 : oj.Count, Date = d.Date };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets suppose that I have the following simple query var q = from p
I have the following query that retrieve the number of users per country; SELECT
I have the following query that performs a AND on-demand: var products = //
I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
I have table that I insert data with following query (from c# code): INSERT
I have the following sql query that returns the DateTime-formatted information in Month format
I have the following query that runs in my Oracle database and I want
I have the following query that I ran on my database to remove some
I have the following code and got myself confused: I have a query that
I have the following Table elements how do i run a query that reproduce

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.