Print Page | Close Window

Finding most recent record

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=788
Printed Date: 13-Sep-2025 at 10:14am


Topic: Finding most recent record
Posted By: BillG
Subject: Finding most recent record
Date Posted: 27-Apr-2008 at 3:52pm
In SQL, I would use the MAX function to find the most recent case for a member.  Is there an easy way to do it with Entities and OQL or do I have to use a SQL query or stored procedure?
 
BillG
 



Replies:
Posted By: davidklitzke
Date Posted: 29-Apr-2008 at 9:46am
Use a PassthroughRdbQuery,


Posted By: pnschofield
Date Posted: 29-Apr-2008 at 9:51am
Try something like this:

RdbQuery query = new RdbQuery(typeof(Case));
query.AddClause(Case.MemberIdEntityColumn, EntityQueryOp.EQ, mMember.MemberID);
query.AddOrderBy(Case.CaseDate, ListSortDirection.Descending);
query.Top = 1;
Case mostRecentCase = PM.GetEntity<Case>(query);

When you sort the cases for a member by date, descending, the top 1 record will be the most recent.

Paul


Posted By: pnschofield
Date Posted: 29-Apr-2008 at 9:52am
Simul-posted with David!

David, would the top-1 approach work?



Print Page | Close Window