ContainsKey throws an exception when key is not a string but is serialized as a string

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 2.22.0
    • Affects Version/s: 2.20.0
    • Component/s: LINQ3
    • None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Since changing the version of the LINQ driver to v3 we receive this error, in v2 everything was working fine. The main problem seems to be that the key of the dictionary is a enum (which is mapped to a string with a RegisterClassMap).

      How to Reproduce

      Query: 

      Collection.AsQueryable<Translation>.Where(x => x.Languages.ContainsKey(language)).ToListAsync(token);

       

      Mapping:

       

                BsonClassMap.RegisterClassMap<Translation>(doc =>
                  {
                      doc.AutoMap();
                      doc.SetIgnoreExtraElements(true);
                      doc.MapIdMember(a => a.Id)
                          .SetIdGenerator(new StringObjectIdGenerator())
                          .SetSerializer(new StringSerializer(BsonType.ObjectId));
                      doc.MapMember(a => a.Languages)
                          .SetSerializer(new DictionaryInterfaceImplementerSerializer<Dictionary<Languages, string>>(
                              DictionaryRepresentation.Document, new EnumSerializer<Languages>(BsonType.String), new StringSerializer()
                          ));
                  });
      

       

       

              Assignee:
              Robert Stam
              Reporter:
              Brecht Vanhaesebrouck
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: