-
Type: Bug
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: 2.19.0
-
Component/s: None
-
None
Summary
Since 2.19 now defaults to LINQ V3, I now have several broken queries, which I expected. However, some of them still fail when I switch back to the LINQ V2 translator.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
2.19
How to Reproduce
Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.
private static string GetFieldName<TDocument>(Expression<Func<TDocument, object>> expression) where TDocument : class { var def = new ExpressionFieldDefinition<TDocument, object>(expression); var rendered = def.Render(BsonSerializer.LookupSerializer<TDocument>(), BsonSerializer.SerializerRegistry, true); return rendered.FieldName; } [Fact] public void GetFieldName_NestedValue() { var field = GetFieldName<Foo>(x => x.Subdocument.NestedProperty); Assert.Equal("Subdocument.NestedProperty", field); } [Fact] public void GetFieldName_ArrayWithIndex() { var field = GetFieldName<Foo>(a => a.ArrayField[-1]); Assert.Equal("ArrayField.$", field); }
Additional Background
The $ array one tells me to use `.FirstMatchingElement()` instead, which is fine for transitioning to v3 but I didn't expect v2 to start failing.
The nested property one throws :
MongoDB.Driver.Linq.ExpressionNotSupportedException
Expression not supported: Convert(x.Subdocument.NestedProperty, Object).
It starts working if I pass in a 2nd type to my helper for the field type to use instead of `object`...but I don't want to have to specify the type every time.
These changes in behavior on V2 lead to me having to schedule time to do a thorough audit of our use of Mongo to avoid runtime problems that may not be caught by tests.
- duplicates
-
CSHARP-4499 Support Convert calls to a base type in filter translators
- Closed
- is related to
-
CSHARP-4543 Unsupported expression - negative indexes
- Closed