-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 2.4.4
-
Component/s: Serialization
-
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.
- related to
-
CSHARP-3350 Improve types handling
- Closed