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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:52:21+00:00 2026-06-14T00:52:21+00:00

I have a MongoDB database where I store all pictures and when I retrieve

  • 0

I have a MongoDB database where I store all pictures and when I retrieve them I have stored some doubles, which ain’t so good, but anyway I want to show only distinct elements.

 @foreach (Foto f in fotos.Distinct(new IEqualityComparer<Foto> { )

But the Foto class has one property called smallurl and I want to show only distinct elements by this property. So how to write a custom IEqualityComparer.

  • 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-14T00:52:23+00:00Added an answer on June 14, 2026 at 12:52 am

    Create your own:

    public class FotoEqualityComparer : IEqualityComparer<Foto>
    {
        public bool Equals(Foto x, Foto y)
        {
             return x.smallurl.Equals(y.smallurl);   
        }
    
        public int GetHashCode(Foto foto)
        {
             return foto.smallurl.GetHashCode();
        }
    }
    

    And use it like so:

    fotos.Distinct(new FotoEqualityComparer());
    

    EDIT:

    There’s no inline lambda overload of .Distinct() because when two objects compare equal they must have the same GetHashCode return value (or else the hash table used internally by Distinct will not function correctly).

    But if you want it in one line, then you could also do grouping to achieve the same result:

    fotos.GroupBy(f => f.smallurl).Select(g => g.First());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MongoDB DB with some data. That all works fine, the data
I have a MongoDB database with audio files stored in GridFS. HTML5 audio tag
I am writing a Happstack server and I have a MongoDB database to connect
In MongoDB I have a query which looks like this to find out for
I have dates stored in MongoDB using Date(), MongoDB uses UTC it's date type,
I have an application where I'd like to use a NoSQL database, but I
I am using mongodb as my backend. I have to store similar document ids
I have a system that stores data into a MongoDB database. Now I need
I have an application that runs on Ubuntu Linux 12.04 which needs to store
I have a number of MongoDB collections which take a number of JSON documents

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.