1

I am developing a program using Microsoft Azure Mobile Service.

On the client side I have queried two different MobileServiceCollection data, and I'm trying to compare them in the client application.

private MobileServiceCollection<StaffRecord, StaffRecord> unCheckinRecords 
//local data
private MobileServiceCollection<StaffRecord, StaffRecord> pollUncheckinRecords; 
//polled latest data

I would like to compare my polled data with the local data. First I tried to use the .Contains provide by MobileServiceCollection

foreach (StaffRecord record in unCheckinRecords)
{
    if (pollUncheckinRecords.Contains(record))  //if the record is no more in uncheckin status
    {
        listRecordIDs.Add(record.ID);
    }
}

These two list suppose to have only one different record only, however, when iterate through by the foreach loop, .Contains return false for every single record. It seems not comparing the objects in the list.

I tried another approach. I convert pollUncheckinRecords to List

foreach (StaffRecord record in unCheckinRecords)
{         
    listPollUncheckinRecords.Remove(record);
}

Yet it doesn't work with a list of StaffRecord as well. None of the records where removed.

Does anyone know what's wrong here? How to compare the object items in the MobileServiceCollection?

Wendy Lin
  • 65
  • 6
  • 1
    `StaffRecord` should [implement `IEquatable`](http://stackoverflow.com/a/3638114/43846) for `Contains(…)` to work, or at the very least must override `Equals()` and `GetHashCode()` – stuartd Apr 20 '15 at 10:04
  • Just hash all the fields you have as in http://stackoverflow.com/a/263416/43846 – stuartd Apr 20 '15 at 10:39
  • Thanks!! It works with IEqualtable implemented, both Contains and Remove works now. – Wendy Lin Apr 27 '15 at 07:32

0 Answers0