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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:47:05+00:00 2026-06-17T16:47:05+00:00

I have an IEnumerable<T> that has a Created field, which is a date. There

  • 0

I have an IEnumerable<T> that has a Created field, which is a date.
There can be multiple T‘s per date and sometimes there are no T‘s for a given date.

Currently I’m grouping these by the date, which gives me all the dates that have at least one T, and the T‘s under them.

What I want though, is something I can use as part of a query that will get me all dates within a range, regardless of whether there are any T‘s with the given date.

Current Code:

var adjustments = DAL.GetAdjustmentsInDateRange(Start, End);

from adjustment in adjustments
group adjustment by adjustment.Created.Date into adjustmentsByDay
orderby adjustmentsByDay.Key descending
select ....

Here, adjustmentsByDay doesn’t have all dates between Start and End. What I want is for it to include them, with no elements.

How can I do that?

  • 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-17T16:47:05+00:00Added an answer on June 17, 2026 at 4:47 pm

    I’ve put together a general-purpose LINQ-to-objects extension method to insert missing things into a sequence:

    public static IEnumerable<T> InsertMissing<T, U>(this IEnumerable<T> source,
        Func<T, U> key, Func<U, U> increment, Func<U, T> create)
    {
        bool first = true;
        U last = default(U);
    
        foreach (var ig in source)
        {
            U current = key(ig);
    
            if (first)
            {
                first = false;
                last = current;
                yield return ig;
                continue;
            }
    
            while (!(last = increment(last)).Equals(current))
            {
                yield return create(last);
            }
    
            yield return ig;
        }
    }
    

    You’ll also need a custom implementation of IGrouping:

    class EmptyGrouping<K, E> : IGrouping<K, E> {
        public K Key { get; set; }
    
        public IEnumerator<E> GetEnumerator() {
            return Enumerable.Empty<E>().GetEnumerator();
        }
    
        IEnumerator IEnumerable.GetEnumerator() {
            return this.GetEnumerator(); 
        }
    }
    

    Then you’ll need to end your query after the orderby, follow it with this call, and then put your select afterwards:

    var allGroups = query.InsertMissing(
        // Key selector
        g => g.Key,
        // Get next desired key from current key
        d => d.AddDays(-1),
        // Create item for missing key
        d => new EmptyGrouping<DateTime,YourAdjustmentType>{ Key = d });
    

    This will go haywire if your keys aren’t ordered or if one of them doesn’t fall in the correct place (e.g. in your case, isn’t on midnight).

    This has the advantage of not needing multiple queries on the original source to determine the min/max values in order to generate a list of keys, and then a further query to join and get the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a WCF service which returns IEnumerable<CyberResourceProvisioningAction> . The CyberResourceProvisioningAction type has
I have an IEnumerable, listOfOnes, and an IEnumerable, listOfTwos. Assuming that I can compare
I have async methods that returns an objects public static IEnumerable<Users.User> GetUsers(IEnumerable<string> uids, Field
I have a class Exporter which has a generic method which accepts an IEnumerable<T>
I have created a CompositeDataBoundControl that i can databind perfectly well. Now i want
I have created an application which has the following: A database created in VS2008,
I have a Profile class that has a father property which self references to
I have a view model in asp .net mvc 3 which has IEnumerable<HttpPostedFileBase> files
I have a collection that is IEnumerable<Transaction> . Transaction has several properties such as
If I have an IEnumerable object in my .net code that contains a single

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.