public static void CopyDespatchThroughputToDB(List <despatchExport> dataSet) { ConnectDbEntities connect = null; try { connect = new ConnectDbEntities(); connect.Configuration.AutoDetectChangesEnabled = false; int count = 0; foreach (var line in dataSet) { ++count; var record = new SeatThroughputHourlyResultSet(); record.WorksOrderNumber = line.WorksOrderNumber; record.CommercialNote = line.CommercialNote; record.SerialNumber = line.SerialNumber; record.TransactionDate = line.TransactionDate; record.PartNumber = line.PartNumber; record.PartDescription = line.PartDescription; record.PaxCount = line.PaxCount; record.Batch = line.Batch; record.BatchLocation = line.BatchLocation; record.CurrentBatchLocation = line.CurrentBatchLocation; record.Username = line.Username; record.MethodType = line.MethodType; record.DefaultLocationCode = line.DefaultLocationCode; record.ProductGroupCode = line.ProductGroupCode; record.RespCode = line.RespCode; connect = AddToContextSeatThroughput(connect, record, count, 500, true); } connect.SaveChanges(); } finally { if (connect != null) { connect.Dispose(); } } }
private static ConnectDbEntities AddToContextSeatThroughput(ConnectDbEntities context, SeatThroughputHourlyResultSet entity, int count, int commitCount, bool recreateContext) { context.Set <SeatThroughputHourlyResultSet>().Add(entity); if (count % commitCount == 0) { context.SaveChanges(); if (recreateContext) { context.Dispose(); context = new ConnectDbEntities(); context.Configuration.AutoDetectChangesEnabled = false; } } return(context); }