private async Task GeneraDataFor(AccidentStatisticDbContext context, IReadOnlyList <AccidentStatistic> accidentStatistics) { _logger.Information($"Inserting '{accidentStatistics.Count}' records into the database"); var accidents = new List <AccidentStatisticDb>(); var vehicles = new List <VehicleDb>(); var casualties = new List <CasualtyDb>(); foreach (var accidentStatistic in accidentStatistics) { AccidentStatisticDb newAccidentStatistic = accidentStatistic.ConvertFrom(); accidents.Add(newAccidentStatistic); vehicles.AddRange(newAccidentStatistic.Vehicles); casualties.AddRange(newAccidentStatistic.Casualties); } await context.BulkInsertAsync(accidents); _logger.Debug($"Inserting Vehicles '{vehicles.Count}' records into the database"); await context.BulkInsertAsync(vehicles); _logger.Debug($"Inserting Casualties '{casualties.Count}' records into the database"); await context.BulkInsertAsync(casualties); _logger.Debug("Saving all bulk inserted records"); await context.BulkSaveChangesAsync(); _logger.Debug("All bulk inserted records saved"); }
private static void ConvertCasualties(this AccidentStatisticDb accidentStatisticDb, AccidentStatistic tflAccidentStatistic) { foreach (var accidentStatisticCasualty in tflAccidentStatistic.Casualties) { accidentStatisticDb.Casualties.Add(accidentStatisticDb.ConvertFrom(accidentStatisticCasualty)); } }
private static void ConvertVehicles(this AccidentStatisticDb accidentStatisticDb, AccidentStatistic tflAccidentStatistic) { foreach (var accidentStatisticVehicle in tflAccidentStatistic.Vehicles) { var newVehicle = accidentStatisticDb.ConvertFrom(accidentStatisticVehicle); accidentStatisticDb.Vehicles.Add(newVehicle); } }
public static VehicleDb ConvertFrom(this AccidentStatisticDb accidentStatistic, Vehicle vehicle) { var result = new VehicleDb { AccidentStatistic = accidentStatistic, VehicleType = vehicle.VehicleType }; return(result); }
public static CasualtyDb ConvertFrom(this AccidentStatisticDb accidentStatistic, Casualty casualty) { var result = new CasualtyDb { AccidentStatistic = accidentStatistic, Age = casualty.Age, AgeBand = casualty.AgeBand, Class = casualty.Class, Mode = casualty.Mode, Severity = casualty.Severity }; return(result); }
public static AccidentStatisticDb ConvertFrom(this AccidentStatistic accidentStatistic) { var result = new AccidentStatisticDb { TflId = accidentStatistic.Id, Borough = accidentStatistic.Borough, Date = accidentStatistic.Date, Latitude = accidentStatistic.Latitude, Longitude = accidentStatistic.Longitude, Location = accidentStatistic.Location }; result.ConvertVehicles(accidentStatistic); result.ConvertCasualties(accidentStatistic); Enum.TryParse(accidentStatistic.Severity.ToString(), true, out Severity severity); result.Severity = severity; return(result); }