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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:04:27+00:00 2026-06-18T07:04:27+00:00

Curious problem, not sure how to do this in linq. Part of the problem

  • 0

Curious problem, not sure how to do this in linq. Part of the problem might be that I’m trying to do this all at once.

I have a phase table

[id, name, [order]]
{{1, 'phase 2', 2}, {2, 'phase 1', 1}

I’d like to get a percentage of progress through all the phases for a given phaseid.

I know of a way to do this with sql.

SELECT (SELECT a.row
        FROM   [phase] p 
               INNER JOIN (SELECT Row_number() 
                                    OVER( 
                                      ORDER BY [order]) row,
                                  id 
                           FROM   [phase]) p2 
                       ON p2.id = p.id 
        WHERE  p.id = @phaseid) / CONVERT(FLOAT, Count(*)) 
FROM   [phase] 

Is there a way to do this in linq? All my attempts seem to fail

  • 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-18T07:04:28+00:00Added an answer on June 18, 2026 at 7:04 am

    Try the following:

    var query = phases.OrderBy(x => x.Order).Select(x => x.Id).ToList();
    var result = query.Select((x, i) => new { x.Id, Index = i + 1 })
                      .Single(x => x.Id == phaseId).Index / (double)query.Count;
    

    It first queries the IDs of all Phases from the database, already correctly ordered. In memory, it then generates the row number and filters out the phase with the requested ID.
    Based on the index and the total count of phases, the percentage is then calculated.

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

Sidebar

Related Questions

I'm curious how others have solved this problem, and what problems might lurk behind
I don't have a problem, I'm just curious. Here is a part of my
I'm pretty sure this is not possible in Zend Framework (I have searched the
Just curious: sure, we all know that the general case of type inference for
Not sure how to call it, but say you have a class that looks
Curious problem. I have a set of images with some attributes that I'd like
I have a curious problem with IE, IIS 6.0 dynamic PNG files and I
I have a curious problem: My app is distributed through ClickOnce. I recently installed
Just curious. I heard something about the new G1GC addressing that latency problem. I
I had a problem that was making the original array to change, the curious

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.