How to fetch Last Record in Subsonic

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 =>;
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.

Leave a Reply

You must be logged in to post a comment.