一次返回20Reading.GetUnProcessReadings().ToList();
笔交易。我需要遍历它,直到它根本没有返回任何交易。
我有以下代码,但我认为它效率不高:
IEnumerable<SSS.ServicesConfig.data.Reading> readings = Reading.GetUnProcessReadings().ToList();;
var gpsreadings = new List<TruckGpsReading>();
do
{
gpsreadings = new List<TruckGpsReading>();
if (readings.Count() > 0)
{
foreach (var reading in readings)
{
Logging.Log("Starting ProcessGpsFile.ProcessReading 3", "ProcessReading", Apps.RemoteTruckService);
var gpsreading = new TruckGpsReading();
gpsreading.DateTimeOfReading = reading.DateTimeOfReading;
gpsreading.Direction = reading.Direction;
gpsreading.DriverNumber = CurrentIniSettings.DriverNumber;
gpsreading.Latitude = (float)reading.Latitude;
gpsreading.Longitude = (float)reading.Longitude;
gpsreading.Speed = reading.Speed;
gpsreading.TruckNumber = CurrentIniSettings.TruckNumber;
gpsreadings.Add(gpsreading);
}
var response = client.SaveGpsReadings(globalSetting.TokenId, globalSetting.SourceId, gpsreadings.ToArray());
if (response != "true")
{
Logging.Log("ProcessGpsFile.ProcessReading: " + response, "ProcessReading", Apps.RemoteTruckService);
}
else
{
Logging.Log("ProcessGpsFile.ProcessReading: Reading.DeleteGpsReadings(readings)", "ProcessReading", Apps.RemoteTruckService);
SSS.ServicesConfig.data.Reading.DeleteGpsReadings(readings);
}
}
readings = Reading.GetUnProcessReadings().ToList();
} while (readings.Count() > 0);
有没有更好的方法来做到这一点?
**编辑* *
public static IEnumerable<Reading> GetUnProcessReadings()
{
try
{
using (var context = new SuburbanEntities())
{
return (from r in context.Readings
where r.IsPublished == false
select r).Take(10).ToList();
}
}
catch (Exception ex)
{
Logging.Log("An error occurred.", "GetPpsSetting", Apps.ServicesConfig, ex);
return null;
}
}