[CSHARP-2460] Support more difficult "Any"s which are nested one into one Created: 21/Dec/18  Updated: 28/Oct/23  Resolved: 04/Mar/19

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: None
Fix Version/s: 2.8.0

Type: Bug Priority: Critical - P2
Reporter: Dmitry Lukyanov (Inactive) Assignee: Dmitry Lukyanov (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

C# linqu quwery


Issue Links:
Related
is related to CSHARP-2012 != operator works incorrect for inter... Closed

 Description   

Original query:

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!!!
        }
    ]
}

3.

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

Even throws error. Inncorrect!

It means "!=" operator does not work properly for internal collection

Note GetAllFor() returns IQueryable<of the class>

Updated description:

1. We do not support difficult All queries if there is an approach to make the same logic via Any.

2. The above example will not compile as syntax error: Any and All methods have the same parameter "s" in the same code scope.

So, the following query should be supported instead of the original one:

GetAllFor().Where(a => a.TenderAlertLotStateList.Any(s => a.TenderAlertLotStateList.Any(s2 => s.TenderAlertStatus != 2))).ToList();

 



 Comments   
Comment by Githook User [ 04/Mar/19 ]

Author:

{'name': 'Dmitry Lukyanov', 'email': 'dmitry_lukyanov@epam.com', 'username': 'dmitry-lukyanov'}

Message: CSHARP-2460: Add throwing exception if linq expressions use unreachable query members.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/efeda17a0871b3a068061d45f7f8f472777814b5

Generated at Wed Feb 07 21:42:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.