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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:33:05+00:00 2026-06-15T14:33:05+00:00

I need to synchronize appointments of an online database and a local database. That’s

  • 0

I need to synchronize appointments of an online database and a local database.
That’s my code so far:

        List<Appointment> onlineAppointments = new List<Appointment>();
        List<Appointment> localAppointments = new List<Appointment>();
        Appointment appointment01 = new Appointment(new DateTime(2012, 12, 24, 17, 30, 00), new DateTime(2012, 12, 24, 17, 45, 00), name, 123, "comment", 0, "test", 123, 1, DateTime.Now);
        Appointment appointment02 = new Appointment(new DateTime(2012, 12, 24, 17, 30, 00), new DateTime(2012, 12, 24, 17, 45, 00), name, 123, "comment", 0, "test", 123, 1, DateTime.Now);

        onlineAppointments.Add(appointment01);
        localAppointments.Add(appointment02);

Since I only want to compare some properties of the object I have created an IEqualityComparer:

public class AppointmentEqualityComparer<T> : IEqualityComparer<T> where T : Appointment
{
    #region IEqualityComparer<T> Members

    public bool Equals(T x, T y)
    {
        return (x == null && y == null) || ((x != null && y != null) &&
        (x.getAppointmentStart() == y.getAppointmentStart() &&
        x.getAppointmentEnd() == y.getAppointmentEnd())
        );
    }

    /// </exception>
    public int GetHashCode(T obj)
    {
        if (obj == null)
        {
            throw new ArgumentNullException("obj");
        }

        return obj.GetHashCode();
    }

    #endregion
}

Unfortunately this does not work:

var comparer = new AppointmentEqualityComparer<Appointment>();    
IEnumerable<Appointment> diffOnlineOffline = onlineAppointments.Except(localAppointments, comparer);

Meaning diffOnlineOffline is not empty but it should be since both lists contain the same appointment.

Any idea?

  • 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-15T14:33:07+00:00Added an answer on June 15, 2026 at 2:33 pm

    Your GetHashCode method should use the properties used for equality. At the moment, objects you want to consider equal will probably not have the same hash code.

    You can use something like this:

    public int GetHashCode(T obj)
    {
        return 41 * (41 * (41 * (41 + obj.getAppointmentStart().GetHashCode())) 
        + obj.getAppointmentEnd().GetHashCode());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to synchronize records, say a list of clients, between a local and
I just realized that I need to synchronize a significant amount of data collection
I need to have ALWAYS a background service that will synchronize my Android application
I need a very fast SQLite database acces. Setting parameters this way: PRAGMA synchronize
Need some regular expressions help. So far I have my code working to allow
Im developing a silverlight app and I need to synchronize a list in different
I need to synchronize two tables. Let's assume that the tables contain following columns:
I am working on cleaning up a database and need to synchronize the IDENTITY
I have a set of apps that all need to synchronize with a webservice:
Need help with a query that I wrote: I have three tables Company id

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.