Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How I can get the before-last record using LinqToEntities with 1-2 queries maximum?

Thank you
Posted
Comments
Henry Minute 28-Nov-10 13:02pm    
I think that for you to get an answer, you will have to define what 'before-last record' means.
Tarun.K.S 28-Nov-10 13:08pm    
OP is talking about the second-last record.
TheAteist 28-Nov-10 14:22pm    
I mean, that if there are N records in the table, so I need to get the record number N-1

You don't need linq for this
object = collection[collection.length-1]
 
Share this answer
 
I found the solution:
obj.OrderByDescending(s => s.Id).Take(2).Skip(1).FirstOrDefault();
 
Share this answer
 
Comments
[no name] 29-Nov-10 19:57pm    
This is HUGELY inefficient and unnecessary
TheAteist 26-Apr-11 5:01am    
Why? Can you suggest something else?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900