Example #1
0
        protected void InsertEmployeesBase()
        {
            var provider = GetIntProvider();

            using (var cn = GetConnection())
            {
                DropTable(cn, "Organization");
                provider.CreateTable <Organization>(cn);

                DropTable(cn, "Employee");
                provider.CreateTable <EmployeeInt>(cn);

                var tdg = new TestDataGenerator();
                tdg.Generate <Organization>(5, (record) =>
                {
                    record.Name = tdg.Random(Source.UniqueWidget);
                }, (records) =>
                {
                    foreach (var record in records)
                    {
                        provider.Save(cn, record);
                    }
                });

                var orgIds = cn.Query <int>("SELECT Id FROM Organization").ToArray();

                tdg.Generate <EmployeeInt>(100, (record) =>
                {
                    record.OrganizationId = tdg.Random(orgIds);
                    record.FirstName      = tdg.Random(Source.FirstName);
                    record.LastName       = tdg.Random(Source.LastName);
                    record.Email          = $"{record.FirstName}.{record.LastName}@nowhere.org";
                }, (records) =>
                {
                    foreach (var record in records)
                    {
                        provider.Save(cn, record);
                    }
                });
            }
        }
        private void InitItemTables()
        {
            using (var cn = GetConnection())
            {
                DropTable(cn, "Item");
                DropTable(cn, "ItemType");
                GetIntProvider().CreateTable <ItemType>(cn);
                GetIntProvider().CreateTable <Item>(cn);

                var tdg = new TestDataGenerator();
                tdg.Generate <ItemType>(10, (it) =>
                {
                    it.Name = tdg.Random(Source.WidgetName) + tdg.RandomInRange(100, 999).ToString();
                }, (records) =>
                {
                    foreach (var record in records)
                    {
                        GetIntProvider().Save(cn, record);
                    }
                });
            }
        }