/// <summary> /// 对临时数据进行分组 /// </summary> /// <param name="selectedSummaryLevel">汇总级别</param> /// <param name="notSummaryCols">分组列的配置信息</param> /// <param name="dataSourceTemp">临时数据源</param> /// <returns>IQueryable临时对象</returns> private IQueryable groupBy(string selectedSummaryLevel, List <GroupByColumn> notSummaryCols, IList dataSourceTemp) { #region 通过动态LINQ做汇总 string groupBy = prepareGroupByString(notSummaryCols); //准备group by 字符串 string groupByForDynamicLinq = string.Format("new ({0})", groupBy); string agg = "KEY as KEY, "; //准备汇总字符串,先取出KEY,再汇总字段 string summaryColString = _SummaryInfo.ColumnSummaryInfos[selectedSummaryLevel].IncludeSummaryColumns; agg = agg + prepareAggregationString(summaryColString); agg = agg.TrimEnd(','); string aggByForDynamicLinq = string.Format("new ({0})", agg); IQueryable afterGroupBy = DynamicQueryable.GroupBy( dataSourceTemp.AsQueryable(), groupByForDynamicLinq, "it").Select( aggByForDynamicLinq); #endregion return(afterGroupBy); }
public void GroupBy_Exceptions() { //Arrange var testList = User.GenerateSampleModels(100, allowNullableProfiles: true); var qry = testList.AsQueryable(); //Act Assert.Throws <ParseException>(() => qry.GroupBy("Bad")); Assert.Throws <ParseException>(() => qry.GroupBy("Id, UserName")); Assert.Throws <ParseException>(() => qry.GroupBy("new Id, UserName")); Assert.Throws <ParseException>(() => qry.GroupBy("new (Id, UserName")); Assert.Throws <ParseException>(() => qry.GroupBy("new (Id, UserName, Bad)")); Assert.Throws <ArgumentNullException>(() => DynamicQueryable.GroupBy((IQueryable <string>)null, "Id")); Assert.Throws <ArgumentNullException>(() => qry.GroupBy(null)); Assert.Throws <ArgumentException>(() => qry.GroupBy("")); Assert.Throws <ArgumentException>(() => qry.GroupBy(" ")); Assert.Throws <ArgumentNullException>(() => qry.GroupBy("Id", (string)null)); Assert.Throws <ArgumentException>(() => qry.GroupBy("Id", "")); Assert.Throws <ArgumentException>(() => qry.GroupBy("Id", " ")); }
public IQueryable GroupBy(IQueryable source, string keySelector, string elementSelector, params object[] values) { return(DynamicQueryable.GroupBy(source, keySelector, elementSelector, values)); }