How to Add an System.Predicate<T> to RelationPredicateBucket

Posts   
 
    
Posts: 7
Joined: 18-Jul-2010
# Posted on: 08-Nov-2011 20:39:39   

Hi,

I use LLBLGen pro 3.1 And DataAccessAdapter via VS2008.

I would like to delete some entities by an Expression. I have an Expression<Func<TEntity, bool> for filtering entities. I found DeleteEntitiesDirectly Method from DataAccesAdapter to delete by a predicate. DeleteEntitiesDirectly Method get 2 parameters Type and RelationPredicateBucket. And we can add predicate to RelationPredicateBucket.

So i convert Expression to a predicate by this code:


Expression<Func<TEntity, bool>> filter;
Func<TEntity, bool> func = filter.Compile();
System.Predicate<TEntity> predicate = func.Invoke;

var bucket = new RelationPredicateBucket();
var type = typeof(TEntity);

I try to do this:


bucket.PredicateExpression.Add(predicate);
dataAccessAdapter.DeleteEntitiesDirectly(type, bucket);

But we can't add a System.Predicate to bucket.PredicateExpression. disappointed

What am I doing wrong? How can i do this?

Thanks in Advance Rahman

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Nov-2011 23:42:16   

Hi Rahman,

You can't do that because a PredicateExpression only can contain IPredicate's. So what you are doing is adding the result of some in-memory function's invokes. You don't need this actually, just add the predicates straight:

bucket.PredicateExpression.Add(SomeEntityFields == somevalue); // etcetera
David Elizondo | LLBLGen Support Team