FieldCompareSetPredicate : Get EntityField from EntityField2

Posts   
 
    
rthakur
User
Posts: 10
Joined: 18-May-2017
# Posted on: 18-May-2017 13:04:21   

Hi guys, I have stumbled on a similar problem related to this thread GetMulti using aggregate Sum in predicate (https://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5063). However, I only need to use FieldCompareSetPredicate to solve my problem.

When trying to create a new FieldCompareSetPredicate, it takes IEntityField or IEntityFieldCore in the constructor to identify the table column. I have table columns defined as EntityField2. I am unable to find a way to get EntityField from EntityField2, or IEntityFieldCore from EntityField2. I am using v5 of LLBLGEN.

I also have group by clause in my inner subquery, so I intend to use the below signature for the group by :

public FieldCompareSetPredicate(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfoField, IEntityFieldCore setField, IFieldPersistenceInfo persistenceInfoSetField, SetOperator operatorToUse, IPredicate filter, IRelationCollection relations, string objectAlias, long maxNumberOfItemsToReturn, ISortExpression sorter, bool negate, IGroupByCollection groupByClause);

Sample code I am trying to write :

 bucket.PredicateExpression.Add(
                new FieldCompareSetPredicate(PlanningHistoryFields.CphUpdatedOn,
                    PlanningHistoryFields.CphUpdatedOn.Source("InnerHistory")
                        .SetAggregateFunction(AggregateFunction.Max), SetOperator.In, null));

Compiling error I am receiving : cannot convert from 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' to 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'

Can someone please help my problem?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 18-May-2017 18:04:47   

If you are using the Adapter template set, then EntityField2 can be used since it inherits from EntityFieldCore.

So you can use the following overload:

public FieldCompareSetPredicate(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfoField, IEntityFieldCore setField, IFieldPersistenceInfo persistenceInfoSetField, 
                                        SetOperator operatorToUse, IPredicate filter, IRelationCollection relations, string objectAlias, long maxNumberOfItemsToReturn, 
                                        ISortExpression sorter, bool negate, IGroupByCollection groupByClause)

And use null for the persistenceInfoField.

rthakur
User
Posts: 10
Joined: 18-May-2017
# Posted on: 19-May-2017 07:17:20   

Walaa wrote:

If you are using the Adapter template set, then EntityField2 can be used since it inherits from EntityFieldCore.

So you can use the following overload:

public FieldCompareSetPredicate(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfoField, IEntityFieldCore setField, IFieldPersistenceInfo persistenceInfoSetField, 
                                        SetOperator operatorToUse, IPredicate filter, IRelationCollection relations, string objectAlias, long maxNumberOfItemsToReturn, 
                                        ISortExpression sorter, bool negate, IGroupByCollection groupByClause)

And use null for the persistenceInfoField.

Using null for persistenceInfoField did the trick. I was able to use the above constructor and get the desired output. Thank you for the help!