Using FindMatches with GetEntityTypeFilter()

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 21-Feb-2008 08:07:09   

Hey folks,

I have a collection of entities that all inherit from PolicyEntity. I'd like to get only the entities of a specific type. I thought using the collection FindMatches method with GetEntityTypeFilter would work but it doesn't. I just get a list of indexes... ALL the indexes.

I my working scenario there are 3 entities in the collection all of a different type but all inheriting from PolicyEntity. The result I was expecting was for a list of indexes with just one entry not three.

Is there a way to get only the entities of type X from a collection?


public override void Save(QuoteEntity quote)
    {
        PolicyNegligenceEntity neg = null;

        List<int> indexes = quote.Policy.FindMatches(PolicyNegligenceEntity.GetEntityTypeFilter());
        if (indexes.Count > 0)
            neg = quote.Policy[indexes[0]] as PolicyNegligenceEntity;

        if (neg == null)
            quote.Policy.Add(neg = new PolicyNegligenceEntity());

        neg.PolicyStartDate = PolicyStartDate.SelectedValue.Value;
        neg.BusinessPostcode = BusinessPostcode.Text;
    }

So in the above example the neg == null check always passes because the object is not PolicyNegligenceEntity...

I've found a post claiming this approach works but I must be missing something... http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=10627

(llbl 2.0/adapter/.net 2.0)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Feb-2008 10:31:16   

In v.2.5 you can use a delegate predicate as follows:

       PredicateExpression filter = new PredicateExpression(new DelegatePredicate(
            delegate(IEntityCore toExamine)
            {
                return toExamine.GetType() == typeof(PolicyNegligenceEntity);
            }));

        List<int> indexes = quote.Policy.FindMatches(filter);

In v.2.0 you can try the following:

        PredicateExpression filter = new PredicateExpression(new EntityProperty("LLBLGenProEntityTypeValue") == (int)EntityType.PolicyNegligenceEntity);
        List<int> indexes = quote.Policy.FindMatches(filter);

Both of these solutions will miss out any subType of the PolicyNegligenceEntity. And thus a new method would be developed in v.2.6 to cover this up.

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 22-Feb-2008 00:54:40   

Thanks Walaa, that worked great.