public async Task <World[]> LoadMultipleUpdatesRows(int count) { IDictionary <string, object> parameters = new ExpandoObject(); using (var db = _dbProviderFactory.CreateConnection()) { db.ConnectionString = _connectionString; await db.OpenAsync(); var results = new World[count]; for (int i = 0; i < count; i++) { results[i] = await ReadSingleRow(db); } for (int i = 0; i < count; i++) { var randomNumber = _random.Next(1, 10001); parameters[$"@Random_{i}"] = randomNumber; parameters[$"@Id_{i}"] = results[i].Id; results[i].RandomNumber = randomNumber; } await db.ExecuteAsync(BatchUpdateString.Query(count), parameters); return(results); } }
public async Task <World[]> LoadMultipleUpdatesRows(int count) { using var db = _dbProviderFactory.CreateConnection(); db.ConnectionString = _connectionString; await db.OpenAsync(); using var updateCmd = db.CreateCommand(); using var queryCmd = CreateReadCommand(db); var results = new World[count]; for (int i = 0; i < count; i++) { results[i] = await ReadSingleRow(db, queryCmd); queryCmd.Parameters["@Id"].Value = _random.Next(1, 10001); } updateCmd.CommandText = BatchUpdateString.Query(count); for (int i = 0; i < count; i++) { var id = updateCmd.CreateParameter(); id.ParameterName = $"@Id_{i}"; id.DbType = DbType.Int32; updateCmd.Parameters.Add(id); var random = updateCmd.CreateParameter(); random.ParameterName = $"@Random_{i}"; random.DbType = DbType.Int32; updateCmd.Parameters.Add(random); var randomNumber = _random.Next(1, 10001); id.Value = results[i].Id; random.Value = randomNumber; results[i].RandomNumber = randomNumber; } await updateCmd.ExecuteNonQueryAsync(); return(results); }