Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Converting a lambda into an IPredicate
 

Pages: 1
LLBLGen Pro Runtime Framework
Converting a lambda into an IPredicate
Page:1/1 

  Print all messages in this thread  
Poster Message
Jez
User



Location:
UK
Joined on:
01-May-2006 00:54:18
Posted:
198 posts
# Posted on: 02-Oct-2008 11:34:39.  
Hi Frans,

Is there a method in LinqSupportClasses for converting a lambda to a RelationPredicateBucket? I had a quick look but nothing immediately jumped out at me.

I was hoping to add some extension methods to UnitOfWork2 to do this sort of thing:

Code:
var work = new UnitOfWork2();
work.AddDeleteEntitiesDirectlyCall<Customer>(x => x.Country == "UK");


rather than:

Code:
var work = new UnitOfWork2();
work.AddDeleteEntitiesDirectlyCall(typeof(Customer),
    new RelationPredicateBucket(CustomerFields.Country == "UK")
);


Thanks
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37803 posts
# Posted on: 02-Oct-2008 16:15:11.  
No that's not possible. The lambda is compiled to a delegate so it can't be converted. If you pass an Expression<> you have to parse the expression tree through teh whole linq provider but that's not really going to work I think. You could try with the QueryBuilder.HandleBinaryExpression but I think it's a dead end. The linq provider isn't setup for this: a lambda always have to have context within a larger queryable based query .

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Brandt
User



Location:

Joined on:
04-Apr-2007 17:43:03
Posted:
142 posts
# Posted on: 15-Nov-2008 19:09:57.  
Otis wrote:
No that's not possible. The lambda is compiled to a delegate so it can't be converted. If you pass an Expression<> you have to parse the expression tree through teh whole linq provider but that's not really going to work I think. You could try with the QueryBuilder.HandleBinaryExpression but I think it's a dead end. The linq provider isn't setup for this: a lambda always have to have context within a larger queryable based query .



what about something like this that is done with Entity Framework.

db.OrderItems.DeleteAllOnSubmit(
                             from si in db.OrderItems
                             where !productsInBasket.Contains(si.ProductID)
                             && si.OrderID == order.ID
                             select si
                         );


Just throwing it out there.
Brandt  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37803 posts
# Posted on: 15-Nov-2008 20:47:49.  
Though doesn't that query fetch the set of entities matching the query you pass in first, and then deleting them one by one?

If not, it could be a way, where the query is used to produce a fieldcompareset predicate, though, how such a query would be executed is then another struggle, so I'll leave it as-is for now.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.