private static void ResetFromFixtureSheet(SqlConnectionAdapter conn, IExcelDataReader excelReader)
        {
            var schemas = ReadSchemas(excelReader);

            PopulateAll(conn, schemas);
        }
        private static void PopulateAll(SqlConnectionAdapter conn, List<Schema> schemas)
        {
            foreach (var sql in schemas.Select(s => "disable trigger all on " + s.TableName))
            {
                conn.ExecuteNonQuery(sql);
            }

            foreach (var sql in from s in schemas where s.HasIdentityKey() select "set identity_insert " + s.TableName + " on")
            {
                conn.ExecuteNonQuery(sql);
            }

            schemas.Reverse();
            foreach (var s in schemas)
            {
                var dt = s.DataTable;
                if (dt == null)
                {
                    var sql = s.AsDeleteAllSql();
                    conn.ExecuteNonQuery(sql);
                    continue;
                }
                foreach (DataRow dr in dt.Rows)
                {
                    var sql = s.AsDeleteRowSql(dr);
                    conn.ExecuteNonQuery(sql);
                }
            }
            schemas.Reverse();
            foreach (var s in schemas)
            {
                var dt = s.DataTable;
                if(dt == null)
                {
                    continue;
                }
                foreach (var sql in from DataRow dr in dt.Rows select s.AsInsertSql(dr))
                {
                    conn.ExecuteNonQuery(sql);
                }
            }

            foreach (var sql in from s in schemas where s.HasIdentityKey() select "set identity_insert " + s.TableName + " off")
            {
                conn.ExecuteNonQuery(sql);
            }

            foreach (var sql in schemas.Select(s => "enable trigger all on " + s.TableName))
            {
                conn.ExecuteNonQuery(sql);
            }
        }
        private static void PopulateAll(SqlConnectionAdapter conn, List <Schema> schemas)
        {
            foreach (var sql in schemas.Select(s => "disable trigger all on " + s.TableName))
            {
                conn.ExecuteNonQuery(sql);
            }

            foreach (var sql in from s in schemas where s.HasIdentityKey() select "set identity_insert " + s.TableName + " on")
            {
                conn.ExecuteNonQuery(sql);
            }

            schemas.Reverse();
            foreach (var s in schemas)
            {
                var dt = s.DataTable;
                if (dt == null)
                {
                    var sql = s.AsDeleteAllSql();
                    conn.ExecuteNonQuery(sql);
                    continue;
                }
                foreach (DataRow dr in dt.Rows)
                {
                    var sql = s.AsDeleteRowSql(dr);
                    conn.ExecuteNonQuery(sql);
                }
            }
            schemas.Reverse();
            foreach (var s in schemas)
            {
                var dt = s.DataTable;
                if (dt == null)
                {
                    continue;
                }
                foreach (var sql in from DataRow dr in dt.Rows select s.AsInsertSql(dr))
                {
                    conn.ExecuteNonQuery(sql);
                }
            }

            foreach (var sql in from s in schemas where s.HasIdentityKey() select "set identity_insert " + s.TableName + " off")
            {
                conn.ExecuteNonQuery(sql);
            }

            foreach (var sql in schemas.Select(s => "enable trigger all on " + s.TableName))
            {
                conn.ExecuteNonQuery(sql);
            }
        }
 public ResetDatabase(SqlConnectionAdapter conn)
 {
     _conn = conn;
 }
        private static void ResetFromFixtureSheet(SqlConnectionAdapter conn, IExcelDataReader excelReader)
        {
            var schemas = ReadSchemas(excelReader);

            PopulateAll(conn, schemas);
        }
 public ResetDatabase(SqlConnectionAdapter conn)
 {
     _conn = conn;
 }