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>
- related to
-
CSHARP-2460 Support more difficult "Any"s which are nested one into one
- Closed
-
CSHARP-1356 LINQ .Any(x => !list.Contains(x)) translates incorrectly.
- Closed
-
CSHARP-1543 Query Lambdas: "!a.b.Any()" supported, but "a.b.Any() == false" fails
- Closed