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

Known serializers strategy is sometimes selecting the wrong serializer

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Unknown Unknown
    • 2.15.1
    • None
    • LINQ3
    • None

    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.

      Attachments

        Activity

          People

            robert@mongodb.com Robert Stam
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: