Dynamic List with relations Sort Problem

Posts   
 
    
Samuel
User
Posts: 9
Joined: 04-Dec-2004
# Posted on: 14-Dec-2005 15:43:10   

I'm trying to sort on an aggregate field in a dynamic list with relations.

I just can't seem to get this sort to work, I've tried every combo of entityname for the sort clause (with and without), but always receive the following error.

No value given for one or more required parameters.

I've read through the forum for days with no luck. confused Help from anyone would be much appreciated. Thanks


        Dim fields As New User.HelperClasses.ResultsetFields(3)
        fields.DefineField(DataArchitech.User.OrderFieldIndex.OrgId, 0, "OrgID", "Orders")
        fields.DefineField(DataArchitech.User.OrderDetailFieldIndex.ProductId, 1, "ProductID", "Detail")
        fields.DefineField(DataArchitech.User.OrderDetailFieldIndex.Qty, 2, "TotalQty", "Detail", AggregateFunction.Sum)

        Dim relations As IRelationCollection = New RelationCollection
        relations.Add(DataArchitech.User.EntityClasses.OrderDetailEntity.Relations.OrderEntityUsingOrderId, "Detail", "Orders", JoinHint.None)

        Dim OrgFilter As IPredicateExpression = New PredicateExpression
        OrgFilter.Add(DataArchitech.User.FactoryClasses.PredicateFactory.CompareValue(DataArchitech.User.OrderFieldIndex.OrgId, ComparisonOperator.Equal, 1, "Orders"))

        Dim groupByClause As IGroupByCollection = New GroupByCollection
        groupByClause.Add(fields(0))
        groupByClause.Add(fields(1))

        Dim Sort As ISortExpression = New SortExpression(New SortClause(fields(2), Nothing, SortOperator.Descending, "Detail"))

        Dim DF As DataArchitech.User.FactoryClasses.DAOFactory
        Dim dao As User.DaoClasses.TypedListDAO = DF.CreateTypedListDAO
        Dim dynamicList As New DataTable
        dao.GetMultiAsDataTable(fields, dynamicList, 0, Sort, OrgFilter, relations, True, groupByClause, Nothing, 0, 0)


bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 15-Dec-2005 02:42:18   
Samuel
User
Posts: 9
Joined: 04-Dec-2004
# Posted on: 15-Dec-2005 14:34:29   

Thanks, But that is was I was baseing my code on, however, I'm still getting the error described.

In my example what objectAlias should I use in the sortClause.

I've tried all 3 Orders, Detail, TotalQty

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Dec-2005 15:19:45   

Remove all the object aliases you have been using, you don't need them, then you will end up with:

Dim fields As New User.HelperClasses.ResultsetFields(3)
fields.DefineField(OrderFieldIndex.OrgId, 0, "OrgID")
fields.DefineField(OrderDetailFieldIndex.ProductId, 1, "ProductID")
fields.DefineField(OrderDetailFieldIndex.Qty, 2, "TotalQty", AggregateFunction.Sum)

Dim relations As IRelationCollection = New RelationCollection
relations.Add(OrderDetailEntity.Relations.OrderEntityUsingOrderId)

Dim OrgFilter As IPredicateExpression = New PredicateExpression
OrgFilter.Add(PredicateFactory.CompareValue(OrderFieldIndex.OrgId, ComparisonOperator.Equal, 1))

Dim groupByClause As IGroupByCollection = New GroupByCollection
groupByClause.Add(fields(0))
groupByClause.Add(fields(1))

Dim Sort As ISortExpression = New SortExpression(New SortClause(fields(2), Nothing, SortOperator.Descending))

To simplify things out, examine the query generated at runtime each time you play with aliases, (enable DQE tracing, see 'troubleshooting and debugging' in the manual)

Use column aliases and entities aliases (objects aliases) as you want, but take care of how they are used.

For example when you specify an object alias for the aggregate field. it will be used to access the field upon which the aggregate function will operate. as follows ->

Count(Detail.Qty) as TotalQty

And that's a new column generated in the result set, to have the result set sorted by this column, you would have to reference it's name

Order By TotalQty

This column have no container object to use it as it's object alias.