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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:33:45+00:00 2026-05-18T07:33:45+00:00

I have an Entity with the following fields GUID TaskId, GUID SubTaskId, DateTime Timestamp

  • 0

I have an Entity with the following fields
GUID TaskId,
GUID SubTaskId,
DateTime Timestamp

The TaskId may be one-to-many with the SubTaskId. It’s like a composite key almost.

I would like to write an expression or expressions resulting in the newest among each TaskId
i.e.

TaskId SubTaskId Timestamp
1 A 2010-11-22 15:48:49.727
1 B 2010-11-22 16:24:51.117
2 C 2010-11-15 11:49:05.717
2 D 2010-11-15 14:02:11.467

Would result in a sequence containing only:
TaskId SubTaskId Timestamp
1 B 2010-11-22 16:24:51.117
2 D 2010-11-15 14:02:11.467

This expression works just fine for showing all TaskId’s and TimeStamps

var q1 = 
    from req in myEntity
    orderby req.TaskId
    select new
    {
        req.TaskId,
        req.SubTaskId,
        req.Timestamp
    };

but I would like to show only the latest Timestamp for each TaskId. All my attempts at adding a max to the expression fail. The posting (http://stackoverflow.com/questions/2034800/how-do-you-find-the-group-wise-max-in-linq) seemed close, but I couldn’t translate it into something working. Perhaps a foreach is needed.

  • 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-18T07:33:46+00:00Added an answer on May 18, 2026 at 7:33 am

    How about this?

    var q1 = 
        from req in myEntity
        group req by req.TaskId into g
        let topReq = g.OrderByDescending(r => r.Timestamp).FirstOrDefault()
        select new
        {
            topReq.TaskId,
            topReq.SubTaskId,
            topReq.Timestamp
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following in Entity Framework . Table - Country Fields List item
I have the following entity class (in Groovy): import javax.persistence.Entity import javax.persistence.Id import javax.persistence.GeneratedValue
I have the following entity structure: public class Party { public Int32 PartyId {
I have a problem with the following Linq query using Entity Framework: from o
I have an entity that maps to an external oracle table which is one
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
I have the following table structure which has been imported into the Entity Framework.
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have a table in my database called Task. Task has the following fields:
I have an entity class that has 10 fields. I am using MS Validation

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.