0

I have 3 lists of custom object BiometricLog: uploadedLog, logsFromBiometric and logsToBeUploaded.

All data that matches uploadedLog should be removed from logsFromBiometric, then stored to logsToBeUploaded.

I tried using this code: logsToBeUploaded = logsFromBiometric.Except(uploadedLogs).ToList() but it doesn't work. Am i Missing something or doing something wrong?

Here is my full block of code.

var uploadedLogs = GetUploadedLogs();
var logsFromBiometric = new List<BiometricLog>();
var logsToBeUploaded = new List<BiometricLog>();

int counter = 0;
foreach (XmlNode biometric in biometricElements)
{
    taskArray[counter] = Task<List<BiometricLog>>.Factory.StartNew(() => ConnectAndProcessBiometric(biometric));
    counter++;
}

Task.WaitAll(taskArray);

foreach (var taskitem in taskArray)
{
    logsFromBiometric.AddRange(taskitem.Result);
}

logsFromBiometric.RemoveAll(m => uploadedLogs.Contains(m));

logsToBeUploaded = logsFromBiometric.Except(uploadedLogs).ToList();
elnigno
  • 1,751
  • 14
  • 37
Carlo Lim
  • 35
  • 1
  • 1
  • 7
  • 1
    Please elaborate on "it doesn't work". – elnigno Dec 02 '15 at 10:30
  • It doesn't show any error, but the result is just logsFromBiometric without removing the uploadedLogs. – Carlo Lim Dec 02 '15 at 10:31
  • 1
    what determines the equality between two log objects? once you decide that you need to override Equals and GetHashcode methods in your log class to implement that logic so that Except method can use your comparison instead of the default which compares references. duplicated question contains an example of that and if you search for it there are tens of other similar questions. – Selman Genç Dec 02 '15 at 10:32
  • Aren't you already removing all `uploadedLogs` from `logsFromBiometric` in the penultimate line? – elnigno Dec 02 '15 at 10:34
  • I'd suspect a bug in the `Equals` and/or `GetHashCode` methods of `BiometricLog`. – Jon Hanna Dec 02 '15 at 10:36
  • hi can you give me an example on how to make iequalitycomparer work? – Carlo Lim Dec 02 '15 at 11:35
  • public class BiometricLog { public int LogID { get; set; } public int BiometricID { get; set; } public DateTime LogDateTime { get; set; } public int TransactionType { get; set; } public string Notes { get; set; } } – Carlo Lim Dec 02 '15 at 11:36

0 Answers0