-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 0.9
-
Component/s: None
-
None
-
Environment:MongoDB v 1.6.3
C# Driver version: both Bison and Driver 0.9.1 (from github)
Here is sample code firstly:
----------------------------------------
A a = new A();
a.b = "asd1";
a.c = "asd2";
db.GetCollection<A>("A").Insert(a);
var o1 = db.GetCollection<A>("A").FindOneAs<A>(Query.Wrap(new
{ c = "asd2" }));object selector = new { c = "asd2" }
;
var o2 = db.GetCollection<A>("A").FindOneAs<A>(Query.Wrap(selector));
Assert.IsNotNull(o1); // Success
Assert.IsNotNull(o2); // Fail
----------------------------------------
The problem is when I want to use anonymous type instance as a selector for wrapping query.
Getting o1 I use it in a place of calling, so actualType and nominalType are equals and driver does not insert hierarhy discriminator into query.
sometimes I want to pass filter as argument for functions, so this case anonymous type insance casted to object, so actualType and nominalType are differ, and driver adds discriminator according to this code:
BsonClassMapSerialzier.Serialize(..) line 175.
----------------------------------------
if (actualType != nominalType || classMap.DiscriminatorIsRequired || classMap.HasRootClass) {
var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(nominalType);
var discriminator = discriminatorConvention.GetDiscriminator(nominalType, actualType);
if (discriminator != null)
}
----------------------------------------
I think it would be better if no descriminator applied when using anonymous instance as a subject for wrapping.