Пример #1
0
        public void GroupByRollupGrouping([IncludeDataSources(true,
                                                              TestProvName.AllSqlServer2008Plus,
                                                              TestProvName.AllPostgreSQL95Plus,
                                                              TestProvName.AllOracle,
                                                              TestProvName.AllSapHana)] string context)
        {
            var testData = GroupSampleClass.TestData();

            using (var db = GetDataContext(context))
                using (var table = db.CreateLocalTable(testData))
                {
                    var query = table.Distinct();

                    var grouped = from q in query
                                  group q by Sql.GroupBy.Rollup(() => new { q.Id1, q.Id2 })
                                  into g
                                  select new
                    {
                        IsGrouping = Sql.Grouping(g.Key.Id1) == 1,
                        g.Key.Id1,
                        Count = g.Count()
                    };

                    var result = grouped.ToArray();
                }
        }
Пример #2
0
        public void GroupByGroupingSetsHaving2([IncludeDataSources(true,
                                                                   TestProvName.AllSqlServer2008Plus,
                                                                   TestProvName.AllPostgreSQL95Plus,
                                                                   TestProvName.AllOracle,
                                                                   TestProvName.AllSapHana)] string context)
        {
            var testData = GroupSampleClass.TestData();

            using (var db = GetDataContext(context))
                using (var table = db.CreateLocalTable(testData))
                {
                    var query = table.Distinct();

                    var grouped = (from q in query
                                   group q by Sql.GroupBy.GroupingSets(() => new
                                                                       { Set1 = new { q.Id1, q.Id2 }, Set2 = new { q.Id2 }, Set3 = new { } })
                                   into g
                                   select g)
                                  .Where(gg => gg.Count() > 0)
                                  .Select(g =>
                                          new
                    {
                        g.Key.Set1.Id1,
                        Count = g.Count()
                    });

                    var result = grouped.ToArray();
                }
        }