Let's say this is my table TicketUpdate
in SQL Server with some data inside:
_______________________________
| Id | TicketId | Description |
-------------------------------
| 1 | 5 | desc1 |
| 2 | 6 | desc2 |
| 3 | 5 | desc3 |
| 4 | 5 | desc4 |
| 5 | 6 | desc5 |
I want to retrieve the last row with TicketId = 5
in using Petapoco
.
There are several methods for retrieving single row like FirstOrDefault
which looks like:
db.FirstOrDefault<TicketUpdate>("select * from TicketUpdate where TicketId = 5");
But using this statement it returns the first row with value of TicketId = 5
with a description of desc1
.
My question is how can I retrieve the LastOrDefault
value then? There is no such methods in Petapoco.
Additional info
Temporarily I can retrieve the last row with TicketId = 5
by nesting the query like
select *
from TicketUpdate
where Id = (select MAX(Id) from TicketUpdate where TicketId = 5)
But is there any methods or better approach for finding the last row like we retrieve First row by using FirstOrDefault
method, without nesting the query?