GetEntityTypeFilter does not work on unsaved collection and EntityView

Posts   
 
    
Posts: 1263
Joined: 10-Mar-2006
# Posted on: 25-Apr-2008 02:49:24   

I have different entity types in a collection, that is in memory (never saved to disk).

If I define an EntityView of that colleciton and use GetEntityTypeFilter() as the filter, it will NOT return the matching entities.

I ended up just looping through the collection and checking the type of each object.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 25-Apr-2008 10:01:27   
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 25-Apr-2008 10:51:49   

That will miss subtypes. If you care about them, you can also use:



[Test]
public void FilterOnTypeInMemoryTest()
{
    using(DataAccessAdapter adapter = new DataAccessAdapter())
    {
        EntityCollection toDelete = new EntityCollection();
        UnitOfWork2 uow = CreateTestBatchForSave2(ref toDelete);
        uow.Commit(adapter, true);

        EntityCollectionNonGeneric employees = new EntityCollectionNonGeneric(new EmployeeEntityFactory());
        adapter.FetchEntityCollection(employees, null);

        //IPredicateExpression filter = ClerkEntity.GetEntityTypeFilter();
        PredicateExpression filter = new PredicateExpression(new DelegatePredicate(
            delegate(IEntityCore toExamine)
            {
                return typeof(ClerkEntity).IsAssignableFrom(toExamine.GetType());
            }));


        List<int> clerksFound = employees.FindMatches(filter);
        Assert.AreEqual(2, clerksFound.Count);

        adapter.DeleteEntityCollection(toDelete);
    }
}

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1263
Joined: 10-Mar-2006
# Posted on: 25-Apr-2008 15:24:08   

Ok, thanks.

I mainly wanted to post this in case it was a bug. Walla's post said there was going to be something added/changed for this in 2.6?

Not a big deal, because this does not come up for me often, but would be nice if I could just use GetEntityTypeFilter() and not worry about if there are any 'new' entities in my existing collection that would be missed....

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 25-Apr-2008 16:58:18   

We thought of adding it, but the code in my previous post does exactly what you want: filter in memory on a type, so we left it as-is.

GetEntityTypeFilter is indeed for db-filtering.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1263
Joined: 10-Mar-2006
# Posted on: 12-May-2008 18:30:42   

What about adding a GetEntityTypeFilterInMemory() function?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 12-May-2008 18:51:00   

WayneBrantley wrote:

What about adding a GetEntityTypeFilterInMemory() function?

You don't have to, see my post earlier in the thread with the example how to filter.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1263
Joined: 10-Mar-2006
# Posted on: 12-May-2008 18:53:37   

Sorry for the confusion, I did see your post earlier.

I just thought it might be clearer if that code you posted above was simply put into a GetEntityTypeFilterInMemory() function on the entity so it would be more 'obvious' and 'easy' for developers to do this kind of filter.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 12-May-2008 23:16:12   

In this case, it's a bit redundant. It would bloat the generated code a bit too much in our opinion, as the creation of the filter is very easy and small.

Frans Bouma | Lead developer LLBLGen Pro
colincsb
User
Posts: 18
Joined: 01-Nov-2006
# Posted on: 23-Jun-2009 20:37:13   

I just got caught by this same problem. There is no mention in the documentation I have for version 2.6 that GetEntityTypeFilter() does not work for entities in-memory that have not been saved.

I'm happy to work around this as advised in the post above but perhaps it would be worth making a note of this in the documentation (or is mine out of date?).

Thanks for a great product by the way ... turnaround time for developing against our database is sooo fast because of your product. Most importantly, changes to the schema can be accommodated very quickly and safely. Love it!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 24-Jun-2009 10:39:29   

colincsb wrote:

I just got caught by this same problem. There is no mention in the documentation I have for version 2.6 that GetEntityTypeFilter() does not work for entities in-memory that have not been saved.

I'm happy to work around this as advised in the post above but perhaps it would be worth making a note of this in the documentation (or is mine out of date?).

There's no mention of this in the docs, we'll add such a note, thanks for the suggestion simple_smile

Thanks for a great product by the way ... turnaround time for developing against our database is sooo fast because of your product. Most importantly, changes to the schema can be accommodated very quickly and safely. Love it!

smile Thanks for the kind words! simple_smile

Frans Bouma | Lead developer LLBLGen Pro