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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:40:53+00:00 2026-05-31T16:40:53+00:00

the following code for some bizarre reason gives me a value for each row

  • 0

the following code for some bizarre reason gives me a value for each row in the table. I just want unique values :

public IQueryable<WasteIndicatorItem> FindAllEWC()
{

    var results = (from x in this._db.WasteIndicatorItems
                   orderby x.EWC
                   select x).ToList();



    return results.OrderBy(s => s.EWC).Distinct().AsQueryable();
}

I’ve tried moving the .Distinct() all over the place, before the ToList ETC. What am i doing wrong must be something simple, cheers for reading..

So in my results I get :

13
13
13
12345
12345

rather than :

13
12345

TABLE STRUCTURE IS :

CREATE TABLE [dbo].[WasteIndicatorItem](
    [WasteIndicatorItemId] [int] IDENTITY(1,1) NOT NULL,
    [WasteId] [int] NOT NULL,
    [WasteIndicatorId] [int] NOT NULL,
    [EWC] [varchar](6) COLLATE Latin1_General_CI_AS NOT NULL,
    [WasteHazardCodeId] [int] NOT NULL,
    [Quantity] [money] NOT NULL,
    [Notes] [varchar](4000) COLLATE Latin1_General_CI_AS NULL,
    [EnteredById] [int] NOT NULL,
    [Entered] [datetime] NOT NULL,
    [LastModifiedById] [int] NULL,
    [LastModified] [datetime] NULL,
 CONSTRAINT [PK_IndicatorItem] PRIMARY KEY CLUSTERED 
(
    [WasteIndicatorItemId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
  • 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-31T16:40:54+00:00Added an answer on May 31, 2026 at 4:40 pm

    You have two choices:

    1. Use GroupBy and keep everything on the SQL side (preferred). You would group by the property you’re interested in that defines uniqueness to you.
    2. Use AsEnumerable to bring everything down, then use the overloaded Distinct method that accepts an IEqualityComparer. This usually isn’t a good idea (unless the result set is small) since all the matching results are returned, and less processing is done on the SQL side.

    Implementing the first solution looks like this:

    var results = _db.WasteIndicatorItems
                     .OrderBy(x => x.EWC)
                     .GroupBy(x => x.EWC)
                     .Select(x => x.First());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen the following (bizarre) Javascript rounding function in some legacy code. After googling
The following code draws some points and connects them with lines. I want to
I want to run some code after my form is resized. However, the following
The following code for some reason poradically works. I have checked the URL so
I'm debugging some code and have found the following code snippet and just don't
I have the following code for some user input validation <h:form> <h:inputText value=#{user.input}> <f:validator
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
Today at work we came across the following code (some of you might recognize
Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
We have following code: try { // some code throwing MyException } catch (MyException

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.