-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.17.1
-
Component/s: LINQ3
-
None
Summary
When storing dictionaries as ArrayOfDocuments ([k: 1, v: "v1"}, \{k: 2, v: "v2"}] and trying to access the values of the dictionary, this works for Linq Provider V2, but version 3 throws an ExpressionNotSupported exception with "Expression not supported: y.Value.".
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
C# Driver: 2.17.1
MongoDB 5.0.9 Community
How to Reproduce
Please see attached code file for an extensive sample.
Code:
var settings = MongoClientSettings.FromConnectionString("mongodb://localhost:27017");
settings.LinqProvider = prov;
var client = new MongoClient(settings);
var db = client.GetDatabase("test");
var coll = db.GetCollection<MyDocument>("my_collection");
var result = coll
.AsQueryable()
.Select(x => new
{
Strings = x.DictData.Select(y => y.Value),
})
.ToArray();
Console.WriteLine($"Works for provider version {prov} (returned items: {result.Length})");
foreach (var item in result)
Console.WriteLine(string.Join("; ", item.Strings));
If prov == V2, output is as expected:
Works for provider version V2 (returned items: 2)
Value10; Value11; Value13
Value20; Value21; Value23
If prov == V3, exception is thrown.
Additional Background
The real live example is a more complex linq query with GroupBy statements that build aggregates based on the dictionary values etc. Problem can be circumvented for the moment by using V2, but we want to use V3 whenever possible.
- duplicates
-
CSHARP-4316 LINQ3 incorrect translate for type like as nullable
- Closed