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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:03:33+00:00 2026-06-14T20:03:33+00:00

In my EF model: I make this view: with following LINQ query (with your

  • 0

In my EF model:
enter image description here

I make this view:

enter image description here

with following LINQ query (with your help):

var query = ctx.data.ToList().OrderBy(d => d.Time).
     GroupBy(d => d.Members.StepId).
     SelectMany(g => g.Select((d, place) => new { Time = d.Time, Members = d.Members, PlaceInStep = place + 1 })).
     GroupBy(d => d.Members.TeamId).
     Select(g => new 
     {
         TeamId = g.Key, 
         Name = g.Select(d => d.Members.Teams.TeamName).First(),  
         Members = g.Select(d => new {Time = d.Time, PlaceInStep = d.PlaceInStep, MemberName = d.Members.MemberName}),                    
         TotalTime = g.Aggregate(new TimeSpan(), (sum, nextData) => sum.Add(nextData.Time))
     });

But I’ve two issues:

1. If 2 members in same Step (for ex. before 35 year old) have same time up to milliseconds they must have same place

2. In Members subcollection in result I want to arrange members by StepId and show StepName.

How to modify this query? Thanks.

Edit 1:

I want to take some this:

enter image description here

  • 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-14T20:03:34+00:00Added an answer on June 14, 2026 at 8:03 pm

    SQL Query to calculate correct member place:

    select *, DENSE_RANK() over (partition by StepId order by Time)
    from Members m
    join Data d on m.MemberId =d.MemberId
    

    linq equivalent adopted to existing linq query:

    var query = context.Data.ToList()
        .OrderBy(d=>d.Time)
        .GroupBy(d => d.Members.StepId)
        .SelectMany(g => 
            g.OrderBy(d => d.Time)
            .GroupBy(d => d.Time)
            .SelectMany((x, place) => 
                x.Select(d => new { Time = d.Time, Members = d.Members, PlaceInStep = place + 1 })))
        .GroupBy(d => d.Members.TeamId)
        .Select(g => new
        {
            TeamId = g.Key,
            Name = g.Select(d => d.Members.Teams.TeamName).First(),
            Members = g.Select(d => 
                new 
                { 
                    Time = d.Time, 
                    PlaceInStep = d.PlaceInStep, 
                    MemberName = d.Members.MemberName, 
                    StepName = d.Members.Steps.StepName, 
                    StepId = d.Members.Steps.StepId 
                }).OrderBy(x=>x.StepId),
            TotalTime = g.Aggregate(new TimeSpan(), (sum, nextData) => sum.Add(nextData.Time))
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a view: @model ModelValidation.Models.Appointment @{ ViewBag.Title = Make a Booking; } <h2>
I have the following partial view: @model IEnumerable<Foo> <div id=foo> @foreach (var foo in
I've following EF model: I want to get data in following view: In Data
I have this code App.Model('users').find(function (err, users) { users.forEach(function(user) { console.log(user.username); }); }); //make
I've got an xml structure similar to this: <cars> <car> <make>Ford</make> <model>F-150</model> <year>2011</year> <customs>
We have the following data model: CalendarAppointment 1 <------> * AppointmentRole * <--------> 1
I'm trying to make use of the extended HTML Helper DisplayFor in this View:
Using the razor view engine, I have some code like the following: @Html.TextAreaFor(model =>
I have the following view model: public class MyViewModel { public bool SingleFamily {
I'm trying to make a partial view that acts as the following: When user

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.