Summary
LINQ3 provider throws below exception when using `Unset` on a dictionary key :
Unable to find source-code formatter for language: text. 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
Unhandled exception. MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression must be a constant: value(Program+<>c__DisplayClass0_0).key in o.Keys.get_Item(value(Program+<>c__DisplayClass0_0).key).
MongoDB server version: 5.0.2 (standalone)
MongoDB driver version: 2.19.0
How to Reproduce
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
using MongoDB.Bson; using MongoDB.Driver; using MongoDB.Driver.Linq; // Init. var mongoUrl = new MongoUrl("mongodb://localhost"); var settings = MongoClientSettings.FromUrl(mongoUrl); settings.LinqProvider = LinqProvider.V3; // WORKS WITH V2. var client = new MongoClient(settings); var database = client.GetDatabase("default"); var collection = database.GetCollection<Model>("Models"); // Insert document with key. var id = ObjectId.GenerateNewId(); var key = "key"; var model = new Model(id, new Dictionary<string, string> { [key] = "value" }); collection.InsertOne(model); // ✅ Update value. collection.UpdateOne( Builders<Model>.Filter.Eq(o => o.Id, id), new UpdateDefinitionBuilder<Model>().Set(o => o.Keys[key], "new value")); // ❌ Remove key. collection.UpdateOne( Builders<Model>.Filter.Eq(o => o.Id, id), new UpdateDefinitionBuilder<Model>().Unset(o => o.Keys[key])); record Model(ObjectId Id, Dictionary<string, string> Keys);
- duplicates
-
CSHARP-4562 SortBy failure for dictionary entry in LinqProvider.V3
- Closed