filtering on related entities in an EntityView2

Posts   
 
    
Stephan
User
Posts: 63
Joined: 16-Jan-2007
# Posted on: 22-Mar-2009 19:48:11   

Hi, I have an EntityView2 which is result of a function returning a DefaultView.In this function I also prefetch related entities.

Now I wonder how can a filter on the related entities?

In my code I have the following code to filter on a related entity (main entity is HealthCarePlan and related entity is HealthCarePlanPattern)


hcpFilter = new PredicateExpression(new FieldCompareValuePredicate(HealthCarePlanPatternFields.PatternId, null, ComparisonOperator.Equal, pattern.PatternId));
hcpCollection.Filter = hcpFilter;

this however always return 0, so I wrote a seperate function like


  private bool IsPatternPresentInCollection(int patternId)
    {
        IPredicateExpression patternFilter = new PredicateExpression(new FieldCompareValuePredicate(HealthCarePlanPatternFields.PatternId, null, ComparisonOperator.Equal, patternId));
        EntityView2<HealthCarePlanPatternEntity> view;
        foreach (HealthCarePlanEntity hcp in hcpCollection)
        {
            view = hcp.HealthCarePlanPattern.DefaultView;
            view.Filter = patternFilter;
            if (!view.Count.Equals(default(int)))
            {
                return true;
                break;
            }
        }
        return false;
    }

this is working fine, but I think this is not best practice.

So my question if i have a View including related entities, how to filter on those related entities in this view?

TIA

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Mar-2009 03:12:27   

So my question if i have a View including related entities, how to filter on those related entities in this view?

You can't filter an entityview on a related entity. If you want to do that, you should map a field mapped onto a related field, on LLBLGen Designer (e.g. Order.CompanyName is mapped onto Order.Customer.CompanyName) and filter on that, using EntityProperty. You also could write a custom property that map the related entity field, instead of mpa a field mapped onto related field.

David Elizondo | LLBLGen Support Team
Stephan
User
Posts: 63
Joined: 16-Jan-2007
# Posted on: 23-Mar-2009 20:27:02   

Hi daelmo,

thanks for the info.