LINQ SelectMany operator on Dictionary

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: 2.4.2
    • Component/s: LINQ
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      I'm attempting to use the new 2.4.2 LINQ features in the aggregation pipeline, but my data structures use a lot of dictionaries that need to be unwound. It looks like the driver does not support $unwind generation for dictionaries. Aggregation stage {$unwind : "$TestDictionary" } words wonders in the shell, but calling the query.ToString() function below throws a System.NotSupportedException:

      The collection selector's serializer must implement IBsonArraySerializer: aggregate([]).OfType().Where(to => (to.Name == "TestName")).SelectMany(to => to.TestDictionary)
      

      So I need to pull the whole dictionary locally and then parse it from there. It's not ideal, but there's a workaround. Am I missing something in the attributes or data structure that would allow this to work? If truly not supported, is there a plan to support $unwind via LINQ for Dictionary objects?

      Data storage object:

      public class TestObject
      {
          public string Name {get;set;};
          [BsonDictionaryOptions( DictionaryRepresentation.ArrayOfArrays )]
          public Dictionary<string,string> TestDictionary { get; set; } = new Dictionary<string, string>();
      }
      

      Aggregation query:

      var query = MongoCollection.AsQueryable()
                      .OfType<TestObject>()
                      .Where( to => to.Name == "TestName" )
                      .SelectMany( to => to.TestDictionary );
      
      string queryText = query.ToString();
      

            Assignee:
            Robert Stam
            Reporter:
            Ben
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: