Filtering on Entity Type when not in a hierachy

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 16-Jul-2007 14:25:00   

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

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 16-Jul-2007 15:21:43   

Hi,

As far i know, ther is no built-in predicate witch do that.

GetEntityTypeFilter() uses PK FK to filter on a particular entity type.

Maybe you can modify your schema to creat hierarchy...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-Jul-2007 11:04:37   

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 simple_smile

Frans Bouma | Lead developer LLBLGen Pro
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 17-Jul-2007 11:26:28   

Thanks for that - I was going to using DelegatePredicate but thought I was missing something obvious.

Since noone else else mentioned it in the forums, is this considered an unusual requirement?

Cheers Simon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-Jul-2007 11:30:35   

simmotech wrote:

Thanks for that - I was going to using DelegatePredicate but thought I was missing something obvious.

Since noone else else mentioned it in the forums, is this considered an unusual requirement?

Cheers Simon

I haven't seen it much, but I can imagine it is a requirement sometimes, hence the reason the DelegatePredicate is there, to be able to easily filter sets on whatever aspect you want to filter on of the entity objects, e.g. type.

Frans Bouma | Lead developer LLBLGen Pro