Print Page | Close Window

using Take() in EntityServerQueryInterceptor

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3436
Printed Date: 13-May-2026 at 8:27am


Topic: using Take() in EntityServerQueryInterceptor
Posted By: ajhops
Subject: using Take() in EntityServerQueryInterceptor
Date Posted: 10-May-2012 at 11:08am
I have an EntityServerQueryInterceptor. 
I want to ensure that for a given entity type, any query is sorted by date and only the latest N elements are returned.
I understand how to add a filter, but I don't understand how to use Take() in the FilterQuery override.



Replies:
Posted By: sbelini
Date Posted: 10-May-2012 at 2:42pm
Hi ajhops,
 
In this case, you'd need to alter the query in the interceptor:
 
protected override bool FilterQuery() {
  if (this.Query.QueryableType == typeof(Order)) {
    this.Query = ((EntityQuery<Order>)this.Query).OrderBy(o => o.OrderDate).Take(10);
  }
  return base.FilterQuery();
}
 
Regards,
   Silvio.



Print Page | Close Window