In-Memory version of GetEntityTypeFilter method

Posts   
 
    
csb1965
User
Posts: 12
Joined: 20-Sep-2011
# Posted on: 29-Sep-2011 20:47:47   

I recently got "caught" by something I didn't know in LLBLGen .. namely that Predicates obtained through a call to GetEntityTypeFilter() do not work for in-memory filtering of collections or creation of entity views etc.

This was my fault I guess .. I had used GetEntityTypeFilter() successfully for DB fetches and just assumed that this also worked in-memory ... ooops!

I found the answer on this forum and THEN found the note in the docs but didn't see this anywhere when reading the docs (which may be my fault). Might I suggest making specific cross reference to this aspect in the section on creating entity views or filtering collections etc as well as in the section to help lazy people like me ;-)

Also, I am wondering if the wording on the Filtering on Entity Type section should be a little stronger ... specifically, that GetEntityTypeFilter() will not work on in-memory collections.

Now, the correct solution works beautifully of course .. namely, using the DelegatePredicate to test assignability. I'll repeat the solution here in case anyone finds this thread when searching for an answer ...


// Create a Predicate for filtering in-memory collections etc
// Replace _entity type to filter_ with the type you want found

IPredicateExpression checkEntryFilter = new PredicateExpression(
    new DelegatePredicate(
        delegate(IEntityCore toExamine) {
                return (typeof(_entity type to filter_).IsAssignableFrom(toExamine.GetType()));
         }));

However, I do miss the convenience of using MyEntity.GetEntityTypeFilter() and I find myself reproducing the code snippet above quite often ... so I was wondering how I can automatically create a new method for each generated entity type like GetInMemoryTypeFilter().

I figure that it would be possible to add something to the code generation templates but I have never touched this side of things and I was hoping someone might be able to show me how to do this.

Is this a good idea or is there a better way of doing this using partial classes or something?

Thanks for the great documentation - I am not meaning to infer that it is lacking at all ... just that I know I tended to learn LLBLGen in bits and pieces when I first came to it and this is a bit of a "gotcha" because you only find out at runtime that you've goofed ;-)

Thanks for your help in advance :-)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Sep-2011 00:26:20   

csb1965 wrote:

Might I suggest making specific cross reference to this aspect in the section on creating entity views or filtering collections etc as well as in the section to help lazy people like me ;-)

Also, I am wondering if the wording on the Filtering on Entity Type section should be a little stronger ... specifically, that GetEntityTypeFilter() will not work on in-memory collections.

There is a note in the Advance Filter Usage section. Anyhow we will take into account your suggestion about the documentation simple_smile

csb1965 wrote:

I'll repeat the solution here in case anyone finds this thread when searching for an answer ...

Thanks!

csb1965 wrote:

I figure that it would be possible to add something to the code generation templates but I have never touched this side of things and I was hoping someone might be able to show me how to do this.

A good start is to read the SDK documentation. So give it a try and let us know if you need further help on that.

csb1965 wrote:

Is this a good idea or is there a better way of doing this using partial classes or something?

In theory you could write an in-memory predicate. Download the SourceCode package and take a look into some of the built-in in-memory predicates like the MemberPredicate. So you can write your own InMemoryGetEntityTypeFilter in your generic generated project

csb1965 wrote:

Thanks for the great documentation - I am not meaning to infer that it is lacking at all ... just that I know I tended to learn LLBLGen in bits and pieces when I first came to it and this is a bit of a "gotcha" because you only find out at runtime that you've goofed ;-)

I understand simple_smile Thanks for the feedback.

David Elizondo | LLBLGen Support Team