-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: LINQ3
Given the following models:
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
public class DatabaseObject { public Dictionary<string, DatabaseValueObject> Items { get; set; } = new Dictionary<string, DatabaseValueObject>(); } public class DatabaseValueObject { public string Description { get; set; } = string.Empty; public int Count { get; set; } } public class MappedObject { public List<KeyValuedObject> Items { get; set; } = new List<KeyValuedObject>(); } public class KeyValuedObject { public string Name { get; set; } = string.Empty; public int Count { get; set; } public string Description { get; set; } = string.Empty; }
We'd like to project the dictionary into a list through linq, however any operation on the .Items results in the exception "The exrpession tree is not supported:
{document} {Items}"
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
var client = new MongoClient(connectionstring); var queryable = client.GetDatabase("test").GetCollection<DatabaseObject>("test_collection").AsQueryable(); queryable.Select(n => new MappedObject { Items = n.Items.Select(k => new KeyValuedObject(){ Count = k.Value.Count, Description = k.Value.Description, Name = k.Key }).ToList() }).Dump("Manual projection");
The goal was to have this mapping be done through automapper, which generates a nearly identical query to the manual one above. But since any operation (select, tolist, ..) on the .Items object results in an error, we can't use projections at all.
It might be that projections on subdocuments like this aren't supported at all on the server side if the dictionary keys can't be listed from the client?