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

Discriminator incorrect when using "OfType<>"

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.12.0
    • Affects Version/s: 2.4.4
    • Component/s: Serialization
    • Labels:
      None

      When using OfType<TDerived> on a collection, the "ofTypeFilter" filter of the returned IFilteredMongoCollection<TDerivedDocument> does not generate a correct discriminator.

      Consider this:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      [BsonDiscriminator(RootClass = true)]
      class A {}
      class B : A {}
      
      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      var collection = database.GetCollection<A>("users").OfType<B>();
      

      The "collection" variable will be of type IFilteredMongoCollection<B> with an internal "ofTypeFilter" generating a discriminator looking like this:

      { "_t" : "B" }
      

      where it should have looked like this:

      { "_t" : ["A", "B"] }
      

      Ultimately this leads to a problem when using "upsert". Since parts of the document inserted comes from the filter, the discriminator does so as well. Since it is incorrect rendered, it leads to document in mongo with a wrong discriminator.

      Attached is a small program that reveals the problem.

            Assignee:
            boris.dogadov@mongodb.com Boris Dogadov
            Reporter:
            marloe Martin Lobger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: