I have this in my method:
var qry = db.Forms.Take(4)
.Where(m => m.SateliteID == Id)
.OrderByDescending(m => m.Tanggal)
.ToArray();
What I want is getting the last 4 records from all the records available, but what I get is the first 4 records. What I have done wrong? I thought that command will be the same with this:
SELECT TOP 4 <fields> FROM Forms WHERE sateliteID = Id
ORDER BY tanggal DESC
But it seems they are a different. What should I do to get what I want (the last 4 records instead of the first 4 records)? Thanks in advance for the help.
Move your Take:
var qry = db.Forms.Where(m => m.SateliteID == Id)
.OrderByDescending(m => m.Tanggal)
.Take(4)
.ToArray();
var qry = db.Forms.Where(m => m.SateliteID == Id).OrderByDescending(m => m.Tanggal).Take(4).ToArray();
You should order and than take some results from ordered list. Methods should be called in that kind of order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With