private QueryValue GenerateGroupingItem <TKey, TElement>(IGrouping <TKey, TElement> grouping, QueryGroupingType queryGroupingType)
        {
            var result        = queryGroupingType.CreateNewInstance();
            var keyValue      = this.Convert(grouping.Key, queryGroupingType.Key.PropertyType);
            var elementsValue = this.Convert(grouping.Select(g => g), queryGroupingType.Elements.PropertyType);

            result.SetValue("Key", keyValue);
            result.SetValue("Elements", elementsValue);

            return(result);
        }
示例#2
0
        private QueryCollectionValue RewriteGroupingElements(QueryCollectionValue groupings, LinqLambdaExpression elementSelectorLambda)
        {
            var groupingElementType   = (QueryGroupingType)groupings.Type.ElementType;
            var rewrittenGroupingType = new QueryGroupingType(groupingElementType.Key.PropertyType, elementSelectorLambda.Body.ExpressionType, groupingElementType.EvaluationStrategy);

            var rewrittenGroupings = new List <QueryValue>();

            foreach (var grouping in groupings.Elements.Cast <QueryStructuralValue>())
            {
                QueryCollectionValue elements = grouping.GetCollectionValue("Elements");
                var rewrittenElements         = elements.Select(e => this.EvaluateLambda <QueryValue>(elementSelectorLambda, e));
                var rewrittenGrouping         = rewrittenGroupingType.CreateNewInstance();
                rewrittenGrouping.SetValue("Key", grouping.GetValue("Key"));
                rewrittenGrouping.SetValue("Elements", rewrittenElements);
                rewrittenGroupings.Add(rewrittenGrouping);
            }

            var result = rewrittenGroupingType.CreateCollectionType().CreateCollectionWithValues(rewrittenGroupings);

            return(result);
        }