I'm using EFCore SQLite, when run a simple query with Linq, I notice that the query Take().Last()
does not return what is expected, sample code:
// There are more than 10000 rows in the table
DbSet<DataEntry> set = ctx.Set<DataEntry>();
// this should return the first 20 rows
var current = set.OrderBy(row => row.Id).Take(20);
// first entry is right
long tStart = current.First().Time;
// This should have returned the last entry in the first 20 entries, but instead, it returned the last entry of the entire data set
long tEnd = current.Last().Time;
// so essentially it looks like this:
set.Last().Time == set.Take(20).Last().Time
It looks Last
will return the last entry in the entire backing data set, no matter which query it is based on. How can I fix this?
ToList
oncurrent
before grabbing first and last. ievar current = set.OrderBy(row => row.Id).Take(20).ToList()
– Nkosi Jan 28 '18 at 2:46