simmotech wrote:
I have an EntityCollection<EntityBase2> full of entities of various types. I need to create an EntityView2 that filters just on a particular entity type.
Is there a built-in predicate to do this?
Cheers
Simon
In v2.5 there is, we added a delegatepredicate, which simply executes the delegate you specify, so you can use that to filter on a particular type.
example of it in action:
[Test]
public void DelegatePredicateTest()
{
EntityCollection<CustomerEntity> customers = new EntityCollection<CustomerEntity>();
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(customers, null);
}
Assert.AreEqual(91, customers.Count);
// create a view from all customers which have a customername with length > 20 characters.
EntityView2<CustomerEntity> customersWithLongName = new EntityView2<CustomerEntity>(customers,
new DelegatePredicate(delegate(IEntityCore toExamine) { return ((CustomerEntity)toExamine).CompanyName.Length > 20; }));
Assert.AreEqual(30, customersWithLongName.Count);
}
If you're on v2.0 code, you can create it as well, using a derived class from Predicate, where you simply override InterpretPredicate. That's the method which is called when a predicate is used for in-memory filtering