Take Last 5 Records when I don't have a CreatedAt field

Hello

How can I grab the last 5 records in the table when I don't have a DateTime field for CreatedAt?

I did search on Google, and came across this, but this doesn't seem to work in LINQPad, it says it is unsupported.
.Reverse().Take(5).Reverse()
Any help would be greatly appreciated.

Thank you.

Comments

  • why not just TableNamePlurals.Skip(TableNamePlurals.Count() - 5)? but if you're doing it without ordering by anything, (depending on your datasource) the results are not deterministic - I suggest ordering by PK/ID first.
  • It might help if you would describe the collection you are working with. You want the last 5 based on what?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!