public void CreateDatabase() { using (var con = new SqlConnection(DatabaseContext.GetServerConnection())) { con.Open(); var query = new DatabaseVersionQueries().QueryDictionary[1]; new SqlCommand(query, con).ExecuteNonQuery(); con.Close(); } using (var con = new SqlConnection(DatabaseContext.GetConnection())) { con.Open(); Parallel.ForEach(new DatabaseVersionQueries().QueryDictionary.Where(i => i.Key > 1), i => { new SqlCommand(i.Value, con).ExecuteNonQuery(); }); var insertVersion = $"INSERT INTO DatabaseVersion VALUES ({DatabaseContext.DbVersion})"; new SqlCommand(insertVersion, con).ExecuteNonQuery(); con.Close(); } }
public void UpdateDatabase() { using (var con = new SqlConnection(DatabaseContext.GetConnection())) { con.Open(); var queryList = new DatabaseVersionQueries().QueryDictionary .Where(i => i.Key > GetDbVersion().ToInt()).ToList(); Parallel.ForEach(queryList, query => { new SqlCommand(query.Value, con).ExecuteNonQuery(); }); string updateVersion = $"UPDATE DatabaseVersion SET DbVersion = '{DatabaseContext.DbVersion}'"; new SqlCommand(updateVersion, con).ExecuteNonQuery(); con.Close(); } }