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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:59:23+00:00 2026-05-13T00:59:23+00:00

I have a linq to sql query var items = from p in ctx.bam_Zending_AllInstances

  • 0

I have a linq to sql query

var items = from p in ctx.bam_Zending_AllInstances
    join q in ctx.bam_Zending_CompletedRelationships 
        on p.ActivityID equals q.ActivityID
    join r in ctx.bam_Prestatie_AllInstances 
        on q.ReferenceData equals r.ActivityID
   where q.ReferenceType == "Activity" && 
         p.Zendingnummer == zenderNr
   orderby r.PrestatieCode
   select new Data.BAMPrestatieInstance
        {
            Aanvaard = r.PrestatieAanvaard,
            Contactnummer = r.ContactNr,
            Foutmelding = r.Foutmelding,
            Identificatie = r.Identificatie,
            Ontvangen = r.PrestatieZendingOntvangen,
            Uitvoerdatum = r.Uitvoerdatum,
            ZendingsNr = p.Zendingnummer,
            PrestatieCode = r.PrestatieCode
        };

This returns a list of classes of multiple “r.PrestatieCode”s. “Uitvoerdatum” is a date however, and I need to only have the latest date for each r.PrestatieCode. How should I go about with this? Because I know how to do this in sql, but I can’t seem to find the way to do it in linq.

Need this a lot atm actually,

any help is usefull,

thanks a bunch!

Gr

  • 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-13T00:59:24+00:00Added an answer on May 13, 2026 at 12:59 am

    There is probably a more optimal way, but this will do what you want. With items defined as above:

    var whatYouWant = items
                          .GroupBy(r => r.PrestatieCode)
                          .Select(
                              g => g.Single(
                                  r => r.Uitvoerdatum == g.Max(s => s.Uitvoerdatum)
                              )
                           );
    

    What this does: First it groups your result set by Data.BAMPrestatieInstance.PrestatieCode. Then, from each group with the same Data.BAMPrestatieInstance.PrestatieCode, it extracts the maximum Data.BAMPrestatieInstance.Uitvoerdatum and then finds the unique item with Data.BAMPrestatieInstance.Uitvoerdatum equal to that maximum date. If there is not a unique item with Data.BAMPrestatieInstance.Uitvoerdatum equal to that maximum date you can alter accordingly (use Where instead of Single, for example).

    Let me know if I misunderstood your requirements.

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

Sidebar

Related Questions

No related questions found

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.