[CSHARP-4118] Known serializers strategy is sometimes selecting the wrong serializer Created: 31/Mar/22  Updated: 28/Oct/23  Resolved: 19/Apr/22

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: None
Fix Version/s: 2.15.1

Type: Bug Priority: Unknown
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CSHARP-3989 oDATA $select support with LINQ3 Closed
Case:

 Description   

The following test fails because it uses the serializer from `x.Id` for `"abc"`.

public class CSharp4118Tests : Linq3IntegrationTest
{
    [Fact]
    public void Test()
    {
        var collection = GetCollection<C>();
        var queryable = collection.AsQueryable()
            .Select(x => new { S = "abc", HasId = x.Id != "000000000000000000000000" });
 
        var stages = Translate(collection,queryable);
 
        AssertStages(stages, "{ $project : { S : 'abc', HasId : { $ne : ['$_id', ObjectId('000000000000000000000000')] }, _id : 0 } }")
    } 
 
    private class C
    {
        [BsonRepresentation(BsonType.ObjectId)] public string Id { get; set; }
    }
}
 

Somehow we need to limit the scope of where it is appropriate to deduce that strings need to be serialized using the `x.Id` serializer.

In this example `"abc"` should be serialized using a vanilla `StringSerializer`, while `"000000000000000000000000"` needs to be serialized using the `x.Id` serializer so that it will be converted to an `ObjectId` in the generated MQL.



 Comments   
Comment by Githook User [ 04/May/22 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4118: Limit propagation of known serializers.
Branch: v2.15.x
https://github.com/mongodb/mongo-csharp-driver/commit/d2a5f5916de5ef043f4b5b7ef70a5b0f831363f9

Comment by Githook User [ 19/Apr/22 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4118: Limit propagation of known serializers.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/052d2183309243c0e960447128ea1883a3ca0f45

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