how to get top 5 records in linq with lambda expression

c# entity-framework-6 linq model-view-controller

Question

I need to get top 5 values of one column "Tempreture" at this time stamp like "select top 5 temperature of the tbl_sensors order by desc "

I tried like this, but I don't know how to get top 5

var sensorsVal = DB.tbl_sensors.OrderByDescending(x => x.CurrentTime).FirstOrDefault();
1
-2
6/24/2016 12:53:21 PM

Accepted Answer

var sensorsVal = DB.tbl_sensors.OrderByDescending(x => x.CurrentTime)
                   .Select(x => x.temperature)
                   .Take(5);
2
8/18/2019 7:15:40 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow