I need to update the values and location/other information for 14 million records. I have the 14 million records in interval_list. Each iteration I use the MeterID from the Interval object to get the correct location and multiplier. I than update the location and update the value based on the multiplier. This code takes 4+ hours to run. Is there a better way to do this? Thanks.
foreach (Interval interval in interval_list)
{
var result = from m in meterList
where m.MeterID.Equals(interval.MeterID)
where m.StartDate < (interval.UTCDateTime.ToLocalTime())
where m.FinalDate > (interval.UTCDateTime.ToLocalTime())
select m;
if (result.Count() == 1) //Ignore if > 1
{
int mult1 = result.ElementAt(0).Mult1;
int mult2 = result.ElementAt(0).Mult2;
interval.ServiceID = result.ElementAt(0).Locserv;
// With updating check to see if value is already adjusted by mult
if (interval.Mult1 > 1)
{
interval.Value = interval.Value / interval.Mult1;
interval.Value = interval.Value * mult1;
}
interval.Mult1 = mult1; //MULT1
interval.Mult2 = mult2; //MULT2
}
}
public class Interval
{
public string MeterID { get; set; }
public DateTime UTCDateTime { get; set; }
public float Value { get; set; }
public DateTime LocalDateTime { get; set; }
public string ServiceID { get; set; }
public string Account { get; set; }
public string Rate { get; set; }
public int Mult1 { get; set; }
public int Mult2 { get; set; }
}
public class Meters
{
public string MeterID { get; set; }
public string Locserv { get; set; }
public DateTime StartDate { get; set; }
public DateTime FinalDate { get; set; }
public int Mult1 { get; set; }
public int Mult2 { get; set; }
}