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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:45:38+00:00 2026-06-18T22:45:38+00:00

I have a result coming back from a LINQ statement that looks like this:

  • 0

I have a result coming back from a LINQ statement that looks like this:

 Id dataId dataVal 
 A  1      1000 
 A  2      2000 
 A  3      3000 
 A  3      3001 
 A  3      3002

What I’d like is to just get the 1st item (dataId = 3 and dataVal = 3000)

Here is my query that is generating the above result:

        var myIds = myList
            .Where(a => ListIds.Contains(a.dataId))
            .Select(x=> new 
            {
                Id = x.Id,
                DataId = x.dataId,
                DataValue = x.DataValue
            }).ToList().Distinct();

Do I need to do some grouping or is there an easier way?

  • 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-18T22:45:39+00:00Added an answer on June 18, 2026 at 10:45 pm

    Group your items by dataId, and then select first item from each group:

    var myIds = (from a in myList
                 where ListIds.Contains(a.dataId)
                 group a by a.dataId into g
                 let firstA = g.OrderBy(x => x.DataValue).First()
                 select new {
                    Id = firstA.Id,
                    DataId = g.Key,
                    DataValue = firstA.DataValue
                 }).ToList();
    

    Or with extension methods (it returns first item in original order):

    var myIds = myList
            .Where(a => ListIds.Contains(a.dataId))
            .GroupBy(a => a.dataId)
            .Select(g => new 
            {
                Id = g.First().Id,
                DataId = g.Key,
                DataValue = g.First().DataValue
            }).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that looks like the following coming back from an XHR
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I have a result from a query like the below, which does not have
I have multiple results sets coming back from a server request against a datasource.
I have this data coming from a REST method using jquery's getJSON method. [Date.UTC(2010,0,0,0,0,0,0),
I have the result of one API (FourSquare) giving me this.. [[4e01728f814d9dac7d52b93d,Bark Boutique,40.7143528,-74.0059731],[4d9f92dfaffda35d5db2a748,Bark Boutique,40.7143528,-74.0059731]]
I have a Result object that lets me pass around a List of event
I have a result of a db query in java.sql.ResultSet that needs to be
Let's imagine that I have a result of evaluating XPath expression //node/@*. MSXML6 returns
I have a action result method i would like to run. How can i

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.