Esempio n. 1
0
        public void Select()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = new SelectFrom <DeliveryNote>();

            var gen  = b.GetSqlText();
            var spec = "SELECT * FROM [WH].[DeliveryNote] AS [T0]";

            Assert.Equal(spec, gen);
        }
Esempio n. 2
0
        public void Join()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = new SelectFrom <DeliveryNote>().Join <Supplier>((d, s) => d.SupplierId == s.Id);

            var gen  = b.GetSqlText();
            var spec = "SELECT * FROM [WH].[DeliveryNote] AS [T0] INNER JOIN [WH].[Supplier] AS [T1] ON ([T0].[SupplierId] = [T1].[Id])";

            Assert.Equal(spec, gen);
        }
Esempio n. 3
0
        public void SelectProjection()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = new SelectFrom <DeliveryNote>().Select(d => new { TotalAmount = d.TotalAmount, SupplierName = d.Number });

            var gen  = b.GetSqlText();
            var spec = "SELECT [T0].[TotalAmount] AS TotalAmount, [T0].[Number] AS SupplierName FROM [WH].[DeliveryNote] AS [T0]";

            Assert.Equal(spec, gen);
        }
Esempio n. 4
0
        public void Where()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = new SelectFrom <DeliveryNote>().Where(d => d.TotalAmount > 100 && d.Year == "2017");

            var gen  = b.GetSqlText();
            var spec = "SELECT * FROM [WH].[DeliveryNote] AS [T0] WHERE (([T0].[TotalAmount] > @SqlParam0) AND ([T0].[Year] = @SqlParam1))";

            Assert.Equal(spec, gen);
        }
Esempio n. 5
0
        public void LinQSelect()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = from DeliveryNote d in new SelectFrom()
                    select d;

            var gen  = b.GetSqlText();
            var spec = "SELECT [T0].* FROM [WH].[DeliveryNote] AS [T0]";

            Assert.Equal(spec, gen);
        }
Esempio n. 6
0
        public void OrderBy()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = new SelectFrom <DeliveryNote>()
                    .OrderBy(d => d.SupplierId).ThenByDescending(d => d.Date);

            var gen  = b.GetSqlText();
            var spec = "SELECT * FROM [WH].[DeliveryNote] AS [T0] ORDER BY [T0].[SupplierId] ASC, [T0].[Date] DESC";

            Assert.Equal(spec, gen);
        }
Esempio n. 7
0
        public void LinQSelectJoin()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = from d in new SelectFrom <DeliveryNote>()
                    join s in new SelectFrom <Supplier>() on d.SupplierId equals s.Id
                    select new { d, s };

            var gen  = b.GetSqlText();
            var spec = "SELECT * FROM [WH].[DeliveryNote] AS [T0] INNER JOIN [WH].[Supplier] AS [T1] ON ([T0].[SupplierId] = [T1].[Id])";

            Assert.Equal(spec, gen);
        }
Esempio n. 8
0
        public void LinQSelectOrderBy()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = from DeliveryNote d in new SelectFrom()
                    orderby d.SupplierId, d.Date descending
            select d;

            var gen  = b.GetSqlText();
            var spec = "SELECT * FROM [WH].[DeliveryNote] AS [T0] ORDER BY [T0].[SupplierId] ASC, [T0].[Date] DESC";

            Assert.Equal(spec, gen);
        }
Esempio n. 9
0
        public void LinQSelectGroupBy()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = from DeliveryNote d in new SelectFrom()
                    group d by new { d.SupplierId, d.Year } into g
                select new { Supplier = g.SupplierId, Year = g.Year, TotalAmount = DbFunctions.Sum(g.TotalAmount) };

            var gen  = b.GetSqlText();
            var spec = "SELECT [T0].[SupplierId] AS Supplier, [T0].[Year] AS Year, SUM([T0].[TotalAmount]) AS TotalAmount FROM [WH].[DeliveryNote] AS [T0] GROUP BY [T0].[SupplierId], [T0].[Year]";

            Assert.Equal(spec, gen);
        }
Esempio n. 10
0
        public void JoinWithMultipleSelect()
        {
            ExpressionsTests.SetModeling();
            Configuration.SetDialect(new TestDialect());
            var b = new SelectFrom <DeliveryNote>()
                    .Join <Supplier>((d, s) => d.SupplierId == s.Id)
                    .Select((d, s) => d.Number + s.Name)
                    .GroupBy((d, s) => d.Number + s.Name)
                    .Join <User>((s, u) => s.CreatedBy == u.Id)
                    .Select((s, u) => new { UserName = u.Name })
                    .Select((s, u) => DbFunctions.Count(u.Name))
                    .GroupBy((s, u) => u.Name)
                    .OrderBy((s, u) => u.Name)
                    .Having((s, u) => DbFunctions.Count(u.Name) > 1);

            var gen  = b.GetSqlText();
            var spec = "SELECT ([T0].[Number] + [T1].[Name]), [T2].[Name] AS UserName, COUNT([T2].[Name]) FROM [WH].[DeliveryNote] AS [T0] INNER JOIN [WH].[Supplier] AS [T1] ON ([T0].[SupplierId] = [T1].[Id]) INNER JOIN [LoB].[SecurityProfile] AS [T2] ON ([T1].[CreatedBy_Id] = [T2].[Id]) GROUP BY ([T0].[Number] + [T1].[Name]), [T2].[Name] HAVING (COUNT([T2].[Name]) > @SqlParam0) ORDER BY [T2].[Name] ASC";

            Assert.Equal(spec, gen);
        }