[英]Retrieve huge number of records ( 300000 ) using a c# code from a table (Teradata Database)
[英]retrieve 5 last records from table by C#
我想通過C#代碼在數據庫中檢索我的一個表的5條最后記錄。我不想在Sql Server中使用查詢。 在我的代碼中,我想檢索tt中的5條最后記錄。我該怎么辦? 現在,它檢索所有記錄
var temp = db.Positions.Where(P => P.DeviceID == device.ID);
List<Position> tempPositions = FilterPosition(temp.ToList<Position>());
var tt = FilterStops(tempPositions, new TimeSpan(0, 30, 0), 100);
List<JsonDevicePositionModel> returnPositions = (
from p in tt
select new
JsonDevicePositionModel
{
DeviceID = p.Position.DeviceID,
Latitude = p.Position.Latitude,
Longitude = p.Position.Longitude,
SerialNumber = p.Position.Device.SerialNumber,
Speed = p.Position.Speed,
}).ToList();
// }
return Json(returnPositions, JsonRequestBehavior.AllowGet);
}
如果您不必擔心性能,則可以使用擴展方法Take of Enumerable類:
var tt = FilterStops(tempPositions, new TimeSpan(0, 30, 0), 100).Take(5);
你可以試試 ...
from p in tt.GetRange(tt.Count - 6, 5)
另一種可能性:來自tt.Skyp(tt.Count-5)中的p.Take(5)
var full = FilterStops(tempPositions, new TimeSpan(0, 30, 0), 100);
var tt= full.Skip(full.Count - 5);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.