Print Page | Close Window

Cast string to IEntityQuery

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1383
Printed Date: 22-Sep-2025 at 1:02am


Topic: Cast string to IEntityQuery
Posted By: bigfish
Subject: Cast string to IEntityQuery
Date Posted: 22-Jul-2009 at 12:38am
Is it possible to cast this string as an IEntityQuery:  Manager.Employee.Where(e => e.LastName == "Fuller")
 
EntityManager Manager is already defined.
 
Why am I need to do this?
 
 
I'd like to be able to offer the option to users for searching records, where the object property to search on is user controlled, as is the search filter type.  I've quite easily created the string result for their search request, now would simply like to cast that as IEntityQuery to pass into EntityManager.ExecuteQueryASynch.
 
Any help, advice on a "better way", or pointers to samples much appreciated.



Replies:
Posted By: kimj
Date Posted: 23-Jul-2009 at 2:28pm
Unfortunately it's not possible to convert a string into an EntityQuery.  In a near future release we'll be adding some sort of filtering support to the ObjectDataSource which will do something very similar to what you need, and it looks like we should make this filtering capability a standalone feature and not buried solely within the ODS.
 
For right now, a few options to consider -
 
1) Use a PassthruEsqlQuery instead of an EntityQuery<T>.   Since you're able to easily create a search request string it's not too involved to turn it into Entity SQL.  Note that these queries always use a DataSourceOnly fetch strategy.
 
2) If you're comfortable with LINQ Expressions, you can use the EntityQuery<T> constructor which accepts an Expression, which you've built up for the search request.  This is actually how DevForce will implement this. 


Posted By: kimj
Date Posted: 23-Jul-2009 at 2:43pm
I forgot to mention, although it may not help you here, that there's a new PredicateBuilder in DevForce 5.2.1 which, once you've got your search criteria expression(s), allows you to easily AND and OR them.


Posted By: kimj
Date Posted: 23-Aug-2009 at 5:34pm
DevForce 5.2.2, due the first week of September, will include a new PredicateDescription class which will allow you to dynamically build predicates and create a filtered query.  Here's a sample -
 

      var expr1 = PredicateBuilder.Make(typeof(Product), "UnitPrice", FilterOperator.IsGreaterThanOrEqualTo, 24);
      var expr2 = PredicateBuilder.Make(typeof(Product), "Discontinued", FilterOperator.IsEqualTo, true);
      var query = PredicateBuilder.FilterQuery(_entityManager.Products, expr1.And(expr2));
      var results = _entityManager.ExecuteQuery<Product>((IEntityQuery<Product>)query);
 


Posted By: bigfish
Date Posted: 23-Aug-2009 at 10:58pm
Fantastic!  That will be very powerful.  Will look to work this into my app in Sept when released. 



Print Page | Close Window