Quantcast
Channel: Jigsaw Boys » tutorial
Viewing all articles
Browse latest Browse all 3

How to fetch Last Record in Subsonic

0
0

Is it just me or is Subsonic the topic of discussion right now? :D
I had a need to retrieve the last ID that had been generated in a table; that being, the last “auto increment” ID of a table.

The following example worked a charm using Subsonic and activerecord.

var fetch_ref_id = contract.All().OrderByDescending(c => c.id).Take(1).ToList();
if (iRef_new_id != null)
{
     iRef_new_id = fetch_ref_id[0].id;
}

As you can see, it creates a new list (noted by the ToList()) by connecting to the table “category”, it then selects all results (All()) and then orders the list by Descending and finally, the take(1) simply takes the top record.

I then whack the result (if you have a column called id) into a integer.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images