c# - How to skip last 2 records and get all other records with linq? -
i have table called test:
test: id, createdby, createddate
now want list of test skip last 2 test
. if have e.g. 10 test
want 1 - 8 test , skip test 9 , 10.
this how trying that:
var query = context.test.orderbydescending(t=>t.id).skip(2) // how take other records?
in case: take(8)
with take
, skip
can range want.
e.g:
var query = context.test.orderbydescending(t=>t.id); var allbutthelasttwoelements = query.take(query.count() - 2);
safest way:
var query = context.test.orderbydescending(t=>t.id).tolist(); var allbutthelasttwoelements = query.take(math.max(0,query.count() - 2));
or other way around (depending on requirements)
var query = context.test.orderbyascending(t=>t.id).skip(2);
Comments
Post a Comment