How to filter the data of related table of related table

Posts   
 
    
Posts: 87
Joined: 17-May-2011
# Posted on: 17-Aug-2011 16:29:07   

Hi there I am unable to filter the data of related table of a related table my code is as follows:

ClientActivityCollection oClientActivityCollection = new ClientActivityCollection();
            IPredicateExpression oPredicateExpression = new PredicateExpression();
            IPredicateExpression oPredicateExpressionRelational = new PredicateExpression();
            RelationCollection oRelationCollection = new RelationCollection();
            ISortExpression oSortExpression = new SortExpression();
            IPrefetchPath oPrefetchPath = new PrefetchPath(EntityType.ClientActivityEntity);

            oPredicateExpressionRelational.Add(ClientFields.IsActive != false);
            oPredicateExpressionRelational.AddWithAnd(ClientFields.IsDeleted != true);

            oPredicateExpression.Add(ClientImageFields.PrimaryPhotoFlag == true);
        
            oPrefetchPath.Add(ClientActivityEntity.PrefetchPathClient_).SubPath.Add(ClientEntity.PrefetchPathClientImages, 1, oPredicateExpression);
            
            oPredicateExpression.Clear();

            oPredicateExpression.Add(ClientActivityFields.ClientId == clientId);
            oPredicateExpression.AddWithAnd(new FieldCompareSetPredicate(ClientActivityFields.ClientId2, ClientFields.ClientId, SetOperator.In, oPredicateExpressionRelational, false));
            if (activityType != null)
            {
                oPredicateExpression.AddWithAnd(new FieldCompareRangePredicate(ClientActivityFields.ActivityType, false, activityType.ToArray()));
            }
            oSortExpression.Add(ClientActivityFields.Date | SortOperator.Descending);

            totalActivities = oClientActivityCollection.GetDbCount(oPredicateExpression,oRelationCollection);
            oClientActivityCollection.GetMulti(oPredicateExpression, 0, oSortExpression, oRelationCollection, oPrefetchPath, pageNumber, pageSize);

but i am getting folllowing exception on getmulti function An exception was caught during the execution of a retrieval query: The multi-part identifier "MaterMatchMakersOld.dbo.ClientActivity.ClientID" could not be bound. The multi-part identifier "MaterMatchMakersOld.dbo.ClientActivity.ClientID2" could not be bound. The multi-part identifier Kindly suggest!

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 17-Aug-2011 17:02:07   

I think yo are mis-using: oPredicateExpression.Clear();

Remember that all fetches are done at the end of your code. So any predicates added later to the oPredicateExpression, will in fact be included in the whatever prefetches you have used it in.

oPrefetchPath.Add(ClientActivityEntity.PrefetchPathClient_).SubPath.Add(ClientEntity.PrefetchPathClientImages, 1, oPredicateExpression);

oPredicateExpression.Clear();

oPredicateExpression.Add(ClientActivityFields.ClientId == clientId); oPredicateExpression.AddWithAnd(new FieldCompareSetPredicate(ClientActivityFields.ClientId2, ClientFields.ClientId, SetOperator.In, oPredicateExpressionRelational, false));

Posts: 87
Joined: 17-May-2011
# Posted on: 18-Aug-2011 06:41:45   

Should i remove oPredicateExppression.Clear(); ??

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 18-Aug-2011 10:23:49   

I don't know your business. You should either remove it, or supply the correct relations to realise it.

If you filter on a related table, you should Join (add relations) to that table.

Posts: 87
Joined: 17-May-2011
# Posted on: 19-Aug-2011 08:30:42   

I thanks for the advice I resolved it by creating seperate predicate expression for related entinty