-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.19.0
-
Component/s: LINQ3
-
None
the following code results in an expression not supported exception in LINQ3 while it used to work with LINQ2:
var result = await personQueryable .Select(p => new ValueTuple<string, string>(p.FirstName, p.LastName)) .ToListAsync();
stack trace:
MongoDB.Driver.Linq.ExpressionNotSupportedException HResult=0x80131515 Message=Expression not supported: new ValueTuple`2(p.FirstName, p.LastName) because constructor parameter item1 does not match any property. Source=MongoDB.Driver StackTrace: at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.NewExpressionToAggregationExpressionTranslator.GetMatchingPropertyName(NewExpression expression, String constructorParameterName) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.NewExpressionToAggregationExpressionTranslator.<>c__DisplayClass0_0.<Translate>b__1(ParameterInfo p) at System.Linq.Enumerable.SelectArrayIterator`2.ToArray() at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.NewExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, NewExpression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.ExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.ExpressionToAggregationExpressionTranslator.TranslateLambdaBody(TranslationContext context, LambdaExpression lambdaExpression, IBsonSerializer parameterSerializer, Boolean asRoot) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.SelectMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.ExpressionToPipelineTranslator.Translate(TranslationContext context, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.Translate[TDocument,TOutput](MongoQueryProvider`1 provider, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.MongoQuery`2.ToCursorAsync(CancellationToken cancellationToken) at MongoDB.Driver.IAsyncCursorSourceExtensions.<ToListAsync>d__16`1.MoveNext()
however projecting to a Tuple<> works just fine.
- duplicates
-
CSHARP-4524 Handle projections using constructors for classes that use public fields instead of public properties
- Closed
- is related to
-
CSHARP-4564 Write a custom serializer for ValueTuples
- Closed