Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2012

!= operator works incorrect for internal collection

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.8.0
    • Affects Version/s: None
    • Component/s: Linq
    • None
    • Environment:
      C# linqu quwery
    • Minor Change

      I have collection with element(let it be only one in collection)

      { 
          "_id" : ObjectId("595e083dfe3d9236b8c178bf"), 
          "Version" : NumberInt(0), 
          "CompanyId" : ObjectId("579a15affe3d910de824ea00"), 
          "TenderAlertLotStateList" : [
              {
                  "TenderLotId" : ObjectId("595e077bfe3d9236b8c175be"), 
                  "ClientResponseDescription" : {
                      "ResponseBy" : null, 
                      "ResponseAt" : null, 
                      "ClientResponseType" : NumberInt(2), 
                      "TenderAlertRejectionReasonId" : null
                  }, 
                  "TenderAlertStatus" : NumberInt(0)
              }, 
              {
                  "TenderLotId" : ObjectId("595e0765fe3d9236b8c1759f"), 
                  "ClientResponseDescription" : {
                      "ResponseBy" : null, 
                      "ResponseAt" : null, 
                      "ClientResponseType" : NumberInt(2), 
                      "TenderAlertRejectionReasonId" : null
                  }, 
                  "TenderAlertStatus" : NumberInt(0)
              }, 
              {
                  "TenderLotId" : ObjectId("595e074bfe3d9236b8c1757b"), 
                  "ClientResponseDescription" : {
                      "ResponseBy" : null, 
                      "ResponseAt" : null, 
                      "ClientResponseType" : NumberInt(2), 
                      "TenderAlertRejectionReasonId" : null
                  }, 
                  "TenderAlertStatus" : NumberInt(0)
              }, 
              {
                  "TenderLotId" : ObjectId("595e06eefe3d9236b8c173a9"), 
                  "ClientResponseDescription" : {
                      "ResponseBy" : "apetruc1@gmail.com", 
                      "ResponseAt" : ISODate("2017-07-06T09:54:52.437+0000"), 
                      "ClientResponseType" : NumberInt(1), 
                      "TenderAlertRejectionReasonId" : null
                  }, 
                  "TenderAlertStatus" : NumberInt(2) //<<it is TenderAlertStatus.Archived!!!
              }
          ]
      }
      

      1.

      GetAllFor().Where(a => a.CompanyId == clientCompanyId && a.TenderAlertLotStateList.Any(s => s.TenderAlertStatus != TenderAlertStatus.Archived)).ToList()

      returns 0 elements. Inncorrect!
      2.

      GetAllFor().Where(a => a.CompanyId == clientCompanyId && a.TenderAlertLotStateList.Any(s => !(s.TenderAlertStatus == TenderAlertStatus.Archived))).ToList()

      returns 0 elements. Inncorrect!
      3.

      GetAllFor().Where(a => a.CompanyId == clientCompanyId && a.TenderAlertLotStateList.Any(s => !a.TenderAlertLotStateList.All(s => s.TenderAlertStatus == TenderAlertStatus.Archived))).ToList()

      Even throws error. Inncorrect!

      4.

      GetAllFor().Where(a => a.CompanyId == clientCompanyId && a.TenderAlertLotStateList.Any(s => !s.TenderAlertStatus.Equals(TenderAlertStatus.Archived))).ToList()

      returns the element. Correct. Previous 2 should works in same way
      5.

      GetAllFor().Where(a => a.CompanyId == clientCompanyId && a.TenderAlertLotStateList.Any(s => s.TenderAlertStatus == TenderAlertStatus.Archived))).ToList()

      returns the element. Correct. And also it the same syntaxes as in 1st. Only difference between 5 and 1 is "==" vs "!=".
      It means "!=" operator does not work properly for internal collection

      Note GetAllFor() returns IQueryable<of the class>

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            apetruc@gmail.com anatolii petruchok
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: