예제 #1
0
        public void SelectGroupByHaving()
        {
            Configuration.SetDialect(new TestDialect());
            SetModeling();
            var b = new SelectBuilder();

            b.From <DeliveryNote>();
            b.Select <DeliveryNote>(dn => dn.SupplierId);
            b.Select <DeliveryNote>(dn => DbFunctions.Sum(dn.TotalAmount));
            b.Select <DeliveryNote>(dn => DbFunctions.Count(dn.TotalAmount));
            b.Select <DeliveryNote>(dn => DbFunctions.Min(dn.TotalAmount));
            b.Select <DeliveryNote>(dn => DbFunctions.Max(dn.TotalAmount));
            b.GroupBy <DeliveryNote>(dn => dn.SupplierId);
            b.Having <DeliveryNote>(dn => DbFunctions.Sum(dn.TotalAmount) > 10);

            var gen  = b.GetSqlText();
            var spec = "SELECT [T0].[SupplierId], SUM([T0].[TotalAmount]), COUNT([T0].[TotalAmount]), MIN([T0].[TotalAmount]), MAX([T0].[TotalAmount]) FROM [WH].[DeliveryNote] AS [T0] GROUP BY [T0].[SupplierId] HAVING (SUM([T0].[TotalAmount]) > @SqlParam0)";

            Assert.Equal(spec, gen);
            Assert.Equal(b.Parameters["SqlParam0"], (decimal)10);
        }