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

The Archive Base Latest Questions

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

I have been wrangling with this for a while, but I just can’t find

  • 0

I have been wrangling with this for a while, but I just can’t find a solid example to work from so I’m turning hopefully to the experts. Appreciation in advance for any help.

I have a working SQL query that I need to convert to Linq. Initially, I had a simple linq query driving an MSChart (line chart) that showed the daily ranking of an item in a list. Unfortunately, MSChart doesn’t drop days with null values off the chart, but just connects them to the next day with a non-null value, so I have to replace the nulls with 0s.

The following query does this via a Left, Self Join against the table, where I just grab the distinct list of days (which will include all days). I know I could set up an ancillary table with a list of all days as well, but this should be just as effective in all cases. The SQL that follows works perfectly in SSMS for a specific book/List combination:

select L2.date, ISNULL(L1.ranking,0)  
from (select distinct date from ListItem where ListID = 1) L2  
Left join ListItem L1 on L2.date = L1.date and L1.BookID = 1 and L1.ListID = 1  
order by date

This returns a list of all dates and rankings, with a 0 ranking for any date that no ranking exists. Now in order to bind the chart to this, I believe converting to Linq is the best course.

I would post my attempts so far, but I fear they are woefully wrong. If any more information is necessary, please let me know.

Thanks.

-Dan

  • 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-19T02:50:27+00:00Added an answer on May 19, 2026 at 2:50 am

    Something like this?

    var distinctDates = 
        ListItems
            .Where(li => li.ListId == 1)
            .Select(li => li.date)
            .Distinct();
    
    var list1 = 
        ListItems
            .Where(li => li.BookID == 1 && li.ListID == 1);
    
    var results = 
        distinctDates
            .Join(
                list1,
                d => d,
                li1 => li1.date,
                (d, li1) => new{ date = d, ranking = li1.ranking ?? 0 }
            )
            .OrderBy(x => x.date);
    

    (Made a few changes since 1st rev.)

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

Sidebar

Related Questions

I have been trying for a while now, but I can't figure out how
Have been googling for a while, but I don't find any page which explains
Have been struggling all day trying to make this simple example work using socket.io.
Have been fighting this for two days and am very frustrated but feel like
Have been scatching my head about this - and I reckon it's simple but
I have been searching the web for this, but I havent found any decent
Have been working in Ruby for a while, but usually in the context of
Have been digging around the docs but cannot find if there is a function
Have been using it for a while with CodeIgniter and I can't remember if
Have been searching all over the internet but struggling to find my answer to

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.