New Posts New Posts RSS Feed: Cast string to IEntityQuery
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Cast string to IEntityQuery

 Post Reply Post Reply
Author
bigfish View Drop Down
Newbie
Newbie


Joined: 20-Mar-2009
Location: Australia
Posts: 36
Post Options Post Options   Quote bigfish Quote  Post ReplyReply Direct Link To This Post Topic: Cast string to IEntityQuery
    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.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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. 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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);
 
Back to Top
bigfish View Drop Down
Newbie
Newbie


Joined: 20-Mar-2009
Location: Australia
Posts: 36
Post Options Post Options   Quote bigfish Quote  Post ReplyReply Direct Link To This Post 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. 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down