Print Page | Close Window

Predicate Builder Example

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=2486
Printed Date: 29-Jul-2026 at 3:08pm


Topic: Predicate Builder Example
Posted By: mseeli
Subject: Predicate Builder Example
Date Posted: 04-Feb-2011 at 12:30am
I have a question regarding your example in the documentation about using the Predicate Builder:
finding all Products with either of “Sir Cajun Louisiana”

I would solve the problem as follows

  var _products = new ObservableCollection<Product>();
  var db = NorthwindIBEntities.DefaultManager;
  var li = new List<string>();

  li.Add("Sir");
  li.Add("Cajun");
  li.Add("Louisiana");

  db.GetQuery<Product>().Where(x => li.Contains(x.ProductName)).ExecuteAsync(op => 
            {foreach (var p in op.Results) _products.Add(p);} );

I understand that predicates can do a lot more than what is required in this simple example. 
My question is if there are important reasons not to solve this example in my way.
Where does this query get executed (on the server or the client)?

Markus Seeli 



Replies:
Posted By: sbelini
Date Posted: 16-Feb-2011 at 11:52am

Hi Markus,

Did you try executing your snippet? It won't retrieve any results. (You should be using x.ProductName.Contains(..) )
 
As for where the query gets executed, if it's running against the datasource, it will be executed on the server; if it's against the cache, the execution is in the client.
If you haven't explicitly set QueryStrategy, execution will depend on whether it has been executed previously (and therefore in the QueryCache, which will trigger a cache query) or not.
 
You can find more information on http://drc.ideablade.com/xwiki/bin/view/Documentation/Query-Strategy - QueryStrategy and http://drc.ideablade.com/xwiki/bin/view/Documentation/Entity-Cache - QueryCache  in our DevForce Resource Center.
 
Regards,
   Silvio.



Print Page | Close Window