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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:22:45+00:00 2026-06-06T04:22:45+00:00

First Table is the View and Second is the result I want This below

  • 0

enter image description here

First Table is the View and Second is the result I want

This below query works fine

List<BTWStudents> students = (from V in db.vwStudentCoursesSD
        where classIds.Contains(V.Class.Value)
        select new BTWStudents
                    {
                    StudentId = V.StudentId
                    Amount= V.PaymentMethod == "Cashier Check" ? V.Amount: "0.00"
                    }).Distinct().ToList();

But I changed it to List to add string formatting(see below)

List<BTWStudents> students = (from V in db.vwStudentCoursesSD
        where classIds.Contains(V.Class.Value)
        select new {V}).ToList().Select(x => new BTWStudents
                    {
                    StudentId = V.StudentId
                    Amount= V.PaymentMethod == "Cashier Check" ? String.Format("{0:c}",V.Amount): "0.00"
                    }).Distinct().ToList();

With this Second Query I get this

enter image description here

Why is distinct not working in the second query?

  • 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-06T04:22:46+00:00Added an answer on June 6, 2026 at 4:22 am

    When working with objects (in your case a wrapped anonymous type because you are using Select new {V} rather than just Select V), Distinct calls the object.Equals when doing the comparison. Internally, this checks the object’s hash code. You’ll find in this case, the hash code of the two objects is different even though the fields contain the same values. To fix this, you will need to override Equals on the object type or pass a custom IEqualityComparer implementation into the Distinct overload. You should be able to find a number of examples online searching for “Distinct IEqualityComparer”.

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

Sidebar

Related Questions

I have a first table view and a segue that pushes to another table
I wanted to call webservice first then generates table view, How I can achieve
I have two views.In first view, I have a table view and I am
I am wanting to have a view table that aggregates rows from four tables.
I have a view that returns 2 ints from a table using a CTE.
I have this code in my table view controller (and delegate): - (void)tableView:(UITableView *)tableView
I'm JOINing the results of this query: SELECT twitter_personas.id , 'TwitterPersona' , twitter_personas.name FROM
What I want to do is to have my table view controller appear when
On the Iphone im trying to populate a main table view from a dictionary,
How can I optimize below SQL (simplified view of my complex query.) Ideally, 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.