Dynamic list, filtering on field not in query

Posts   
 
    
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 17-Jun-2005 02:29:11   

to add a field to a dynamic list I do this fields.DefineField(CustomersFieldIndex.CustomerCode, 0, "CustomerCode", "Customers");

To filter on a field I've added I statusclause.Add(new FieldCompareValuePredicate(fields[3], null, ComparisonOperator.Equal, "Pending"));

How do I add a filter on field not in the list? statusclause.Add(new FieldCompareValuePredicate(CustomersFieldIndex.Active, null, ComparisonOperator.Equal, "Y"));

Doesn't work.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 17-Jun-2005 09:42:07   

What does 'doesn't work' mean exactly? You get an error, the filter doesn't filter or something else? You can just add a filter on a field which is not in the resultset, though make sure the field you're filtering on is in the total set of fields defined by the relations/entity of the fields in the resultsetfields.

So if you have just fields from one entity in the resultsetfields and no relations defined, and you want to filter on a field in another entity, specify a relation. If you've specified relations, be sure teh field is in one of the entities included by these relations.

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 17-Jun-2005 13:21:58   

My code looks like this

            
ResultsetFields fields = new ResultsetFields(9);
            fields.DefineField(CustomersFieldIndex.CustomerCode, 0, "CustomerCode", "Customers");
            fields.DefineField(ProvidersFieldIndex.Provider, 1, "Provider","Provs");
            fields.DefineField(SubProviderFieldIndex.SubName, 2, "Subprovider", "Subs");
            fields.DefineField(StatusFieldIndex.Status, 3, "Status","Status");
            fields.DefineField(CgmBanInvoicesFieldIndex.BillYyyymm, 4, "BillYYYYMM","Invs");
            fields.DefineField(DisputeMasterFieldIndex.ClaimReasonCode, 5, "ClaimReasonCode","Disp");
            fields.DefineField(DisputeMasterFieldIndex.CurrentAmount, 6, "Amount", "Disp", AggregateFunction.Sum);
            fields.DefineField(DisputeMasterFieldIndex.StatusId, 7, "Disputes", "Disp", AggregateFunction.Count);
            fields.DefineField(CustomersFieldIndex.Active, 8, "Active", "Customers");
            
            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            bucket.Relations.Add(CustomersEntity.Relations.CgmBansEntityUsingCustomerId, "Customers","Bans",JoinHint.None);
            bucket.Relations.Add(CgmBansEntity.Relations.SubProviderEntityUsingSubProviderIdProviderId,"Bans","Subs", JoinHint.None);
            bucket.Relations.Add(SubProviderEntity.Relations.ProvidersEntityUsingProviderId, "Subs","Provs",JoinHint.None);
            bucket.Relations.Add(CgmBansEntity.Relations.CgmBanInvoicesEntityUsingBanid,"Bans","Invs", JoinHint.None);
            bucket.Relations.Add(CgmBanInvoicesEntity.Relations.DisputeMasterEntityUsingInvoiceId,"Invs","Disp", JoinHint.None);
            bucket.Relations.Add(DisputeMasterEntity.Relations.StatusEntityUsingStatusId,"Disp","Status", JoinHint.None);

            
            IPredicateExpression whereclause = new PredicateExpression();
            whereclause.Add(new FieldCompareValuePredicate(fields[3], null, ComparisonOperator.Equal, "Pending"));
            whereclause.Add(new FieldCompareValuePredicate(fields[8], null, ComparisonOperator.Equal, "Y"));

            bucket.PredicateExpression.Add(whereclause);
            
            IGroupByCollection groupByClause = new GroupByCollection();
            groupByClause.Add(fields[0]);
            groupByClause.Add(fields[1]);
            groupByClause.Add(fields[2]);
            groupByClause.Add(fields[3]);
            groupByClause.Add(fields[4]);
            groupByClause.Add(fields[5]);
            groupByClause.Add(fields[8]);

            DataTable dynamicList = new DataTable();

                adapter.FetchTypedList(fields, dynamicList, bucket, 0, sorter, true, groupByClause);
            return dynamicList;

I don't want to add field[8] to the ResultsetFields, but I can't see how to build the proper field compare predicate. the constructor takes a IEntityField (field[8], here).

whereclause.Add(new FieldCompareValuePredicate(fields[8], null, ComparisonOperator.Equal, "Y"));

How can I replace the fields[8] with something referencing the Entity fiield instead

CustomersFieldIndex.Active

is an enum. How can I get the coresponding field to plug in to the where clause?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Jun-2005 11:52:56   

Why not:


whereclause.Add(PredicateFactory.CompareValue(CustomersFieldIndex.Active, ComparisonOperator.Equal, "Y", "Customers"));

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 19-Jun-2005 00:06:38   

Because I didn't know how to specify and alias here untill you showed me. Thanks, It works.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 19-Jun-2005 10:40:58   

THere are a couple of overloads for the method, one accepting an alias, another accepting an alias and a negate flag etc. Of course not all methods can be documented with an example, though these are documented in the reference manual.

Though this particular case is documented in the manual with an example, see 'advanced filtering'.

Frans Bouma | Lead developer LLBLGen Pro