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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:53:11+00:00 2026-06-10T01:53:11+00:00

I have a problem trying to get a Distinct List of my Class Objects.

  • 0

I have a problem trying to get a Distinct List of my Class Objects.

For this particular query, I am only interested in grabbing the DLType, There are 3 types of ‘DLType’ that appear in my List multiple times. I just want to grab those three types from the data and use it for the datasource for a combo box.

Here is My Class :-

public class DistributionList
{
    public int DistributionID { get; set; }
    public string DistributionName { get; set; }
    public string  DLType { get; set; }
}

Here is where I grab the data:-

public List<DistributionList> GetDistributionLists()
{
    DataTable dt = new DataTable();

    OleDbCommand cmd = new OleDbCommand("Select * FROM [DistributionLists]",
                                                 Connection);
    Adapter.SelectCommand = cmd;

    Connection.Open();
    Adapter.SelectCommand.ExecuteNonQuery();
    Adapter.Fill(dt);
    Connection.Close();

    var DistributionLists = (from d in dt.AsEnumerable()
             select new DistributionList
             {
                 DistributionID = d.Field<int>("DistributionID"),
                 DistributionName = d.Field<string>("DistributionName"),
                 DLType = d.Field<string>("DLType")
             }).ToList();

    return DistributionLists;

}

Here I pull the data into my Form :-

var distributionData = dc.GetDistributionLists();

Now i need to get a distinct list from the distributionData Object:-

var query = (from d in distributionData
                         select new DistributionList
                         {
                             DLType = d.DLType

                         }).Distinct().ToList();

But this doesn’t work, Is there a way of doing this?

  • 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-10T01:53:13+00:00Added an answer on June 10, 2026 at 1:53 am

    The problem with your Linq is that it generates a new DistributionList for each value – and because they’re all different instances, Distinct returns them all. Try reordering the way you process the query, something like this:

    var query = (from d in distributionData select d.DLType)
                      .Distinct()
                      .Select(t => new DistributionList() { DLType = t })
                      .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with this query trying to get a sum and a
Trying to do this with a single query, but want to get a list
Hey all, i have a problem with trying to get 2 forms to close
I'm trying to get a handle on whether we have a problem in our
I have a problem with a page where I am trying to get colorbox
I have a problem in firefox, where I'm trying to get a form submission
I'm trying to get a regexp to solve the next problem: I have some
I have what is likely a simple problem, whereby I am trying to get
I'm trying to get familiar with CI and I have run into a problem
I have a problem trying to stream audio using the AsyncPlayer class in android.

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.