<Generics> Field in PredicateExpression?

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 11-Jul-2007 18:45:47   

I'm trying to create a generic function to get a Predicate

private IPredicateExpression GetPredicate(IEntityFields  Fields, Int SomeID) 
{

     IPredicateExpression select = new PredicateExpression();
     select.AddWithAnd(Fields["ID"] == SomeID); 
     etc....
    return select;
}

But of course fails. How can I add a predicate with a generic IEntityFields?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 11-Jul-2007 19:04:02   

select.AddWithAnd(((EntityField)Fields["ID"]) == SomeID);

or if you're using adapter, cast to EntityField2 simple_smile You can also use new FieldCompareValuePredicate(... )

THe interfaces won't work, as operators can't be defined on interfaces.

Frans Bouma | Lead developer LLBLGen Pro
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 11-Jul-2007 20:19:24   

Along the same line, how do I set a Field value like this:

private void SetStuff(IEntityFields Fields, IEntityCollection Collection) { Collection.GetMulti(some predicate);

         foreach (EntityBase entity in Collection)
         {
             entity.IsNew = true;
        **   entity.Fields["A name of a field"] = a value;**  -- FAILS of course
         }

}

ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 11-Jul-2007 20:23:13   

Found it:

entity.SetNewFieldValue