public void Can_select_limit_on_Table_with_References()
        {
            using (var db = OpenDbConnection())
            {
                CustomerOrdersUseCase.DropTables(db); //Has conflicting 'Order' table
                db.DropAndCreateTable <Order>();
                db.DropAndCreateTable <Customer>();
                db.DropAndCreateTable <CustomerAddress>();

                var customer1 = LoadReferencesTests.GetCustomerWithOrders("1");
                db.Save(customer1, references: true);

                var customer2 = LoadReferencesTests.GetCustomerWithOrders("2");
                db.Save(customer2, references: true);

                var results = db.LoadSelect <Customer>(q => q
                                                       .OrderBy(x => x.Id)
                                                       .Limit(1, 1));

                //db.GetLastSql().Print();

                Assert.That(results.Count, Is.EqualTo(1));
                Assert.That(results[0].Name, Is.EqualTo("Customer 2"));
                Assert.That(results[0].PrimaryAddress.AddressLine1, Is.EqualTo("2 Humpty Street"));
                Assert.That(results[0].Orders.Count, Is.EqualTo(2));

                results = db.LoadSelect <Customer>(q => q
                                                   .Join <CustomerAddress>()
                                                   .OrderBy(x => x.Id)
                                                   .Limit(1, 1));

                db.GetLastSql().Print();

                Assert.That(results.Count, Is.EqualTo(1));
                Assert.That(results[0].Name, Is.EqualTo("Customer 2"));
                Assert.That(results[0].PrimaryAddress.AddressLine1, Is.EqualTo("2 Humpty Street"));
                Assert.That(results[0].Orders.Count, Is.EqualTo(2));
            }
        }
        public void Can_get_GetTableNamesWithRowCounts_of_keyword_table()
        {
            using (var db = OpenDbConnection())
            {
                CustomerOrdersUseCase.DropTables(db); //Has conflicting 'Order' table
                db.CreateTable <Order>();

                3.Times(i => db.Insert(new Order {
                    CustomerId = i + 1, LineItem = $"Field{i+1}"
                }));

                var tableNames = db.GetTableNamesWithRowCounts(live: true);
                Assert.That(tableNames.Count, Is.GreaterThan(0));

                var table1Name = db.GetDialectProvider().GetTableName(typeof(Order).GetModelMetadata()).StripDbQuotes();

                var table1Pos = IndexOf(tableNames, x => x.Key.EqualsIgnoreCase(table1Name) && x.Value == 3);
                Assert.That(table1Pos, Is.GreaterThanOrEqualTo(0));

                tableNames = db.GetTableNamesWithRowCounts(live: false);
                Assert.That(tableNames.Any(x => x.Key.EqualsIgnoreCase(table1Name)));
            }
        }
        public new void TestFixtureSetUp()
        {
            db = base.OpenDbConnection();
            CustomerOrdersUseCase.DropTables(db); //Has conflicting 'Order' table

            db.DropAndCreateTable <Order>();
            db.DropAndCreateTable <Customer>();
            db.DropAndCreateTable <CustomerAddress>();
            db.DropAndCreateTable <Country>();
            db.DropAndCreateTable <AliasedCustomer>();
            db.DropAndCreateTable <AliasedCustomerAddress>();
            db.DropAndCreateTable <OldAliasedCustomer>();
            db.DropAndCreateTable <OldAliasedCustomerAddress>();
            db.DropAndCreateTable <MismatchAliasCustomer>();
            db.DropAndCreateTable <MismatchAliasAddress>();

            db.DropTable <SelfCustomer>();
            db.DropTable <MultiSelfCustomer>();
            db.DropTable <SelfCustomerAddress>();

            db.CreateTable <SelfCustomerAddress>();
            db.CreateTable <MultiSelfCustomer>();
            db.CreateTable <SelfCustomer>();
        }