Beispiel #1
0
        /// <summary>
        /// Generate a new type for the aggregated results and return an instance of the results with the aggregated value.
        /// </summary>
        /// <param name="dataToProject">The results to project.</param>
        /// <param name="alias">The name of the alias to use in the new type.</param>
        /// <param name="aliasType">The type of the alias to use in the new type.</param>
        /// <returns>An instance of the results with the aggregated value as <see cref="IQueryable"/>.</returns>
        private IQueryable ProjectResult(object dataToProject, string alias, Type aliasType)
        {
            var properties = new List <Tuple <Type, string> >()
            {
                new Tuple <Type, string>(aliasType, alias)
            };
            var resType = AggregationTypesGenerator.CreateType(properties.Distinct(new TypeStringTupleComapere()).ToList(), Context, true);

            var objToProject = Activator.CreateInstance(resType);
            var pi           = resType.GetProperty(alias);

            pi.SetValue(objToProject, dataToProject);

            var dataToProjectList = (new List <object>()
            {
                objToProject
            }).AsQueryable();

            return(ExpressionHelpers.Cast(resType, dataToProjectList));
        }
Beispiel #2
0
        /// <summary>
        /// Get the type to use for returning aggregation results in a group-by query.
        /// </summary>
        /// <param name="groupByTrasformation">The group by transformation.</param>
        /// <param name="keyType">The type of a group by key.</param>
        /// <returns>The new dynamic type.</returns>
        private Type GetAggregationResultProjectionType(ApplyGroupbyClause groupByTrasformation, Type keyType)
        {
            if (groupByTrasformation.Aggregate == null)
            {
                throw new ArgumentException("group by without aggregate");
            }
            var keyProperties             = new List <Tuple <Type, string> >();
            var aggregationImplementation = AggregationImplementations <AggregationImplementationBase> .GetAggregationImplementation(groupByTrasformation.Aggregate.AggregationMethod);

            var aliasType = aggregationImplementation.GetResultType(Context.ElementClrType, groupByTrasformation.Aggregate);

            keyProperties.Add(new Tuple <Type, string>(aliasType, groupByTrasformation.Aggregate.Alias));
            foreach (var prop in keyType.GetProperties())
            {
                if (prop.Name == "ComparerInstance")
                {
                    continue;
                }
                keyProperties.Add(new Tuple <Type, string>(prop.PropertyType, prop.Name));
            }

            return(AggregationTypesGenerator.CreateType(keyProperties.Distinct(new TypeStringTupleComapere()).ToList(), Context, true));
        }