SortExpression using new EntityField in Typed List

Posts   
 
    
rtbike
User
Posts: 23
Joined: 23-Jan-2009
# Posted on: 24-Jul-2009 02:41:57   

Hello,

I have a Summed field in my typed list and would like to add it to my sortExpression but just can seem to get the correct sytax? I am using self service.


I would like to sort on this column in my sort Expression

orderFields.DefineField(new EntityField("OrderTotal",
                  new ScalarQueryExpression(CustomerSalesOrderItemFields.AmountCharged.SetAggregateFunction(AggregateFunction.Sum),
                      orderFilter, subSelectRelations)), 7);


ISortExpression orderSort = new SortExpression();
        if(sortOn == "OrderTotal")
        {
            orderSort.Add(What goes here? | SortDirection.Ascending);
        }

I have tryied using the entire ScalarQuery in the sort but just keep missing something

thanks,

Todd

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Jul-2009 09:28:56   

Please try the following:

ISortExpression orderSort = new SortExpression();
        if(sortOn == "OrderTotal")
        {
            orderSort.Add(orderFields[7] | SortDirection.Ascending);
        }
rtbike
User
Posts: 23
Joined: 23-Jan-2009
# Posted on: 24-Jul-2009 21:57:24   

Hi Walaa,

I tried your suggestion but get the error message

"Can not apply operator '|' operands of type SD.LLBLGen.Pro.ORMSupportClasses.IEntityField' and 'System.Web.UI.WebControls.SortDirection',

Candidates are: System.Web.UI.WebControls.SortDirection | (System.Web.UI.WebControls.SortDirection, System.Web.UI.WebControls.SortDirection

Below is the full TypeList


 void LoadOrders(string sortOn)
    {
        ResultsetFields orderFields = new ResultsetFields(8);
        orderFields.DefineField(PreSeasonScheduleFields.ShippingWindowStart, 0, "ShippingWindowStart");
        orderFields.DefineField(PreSeasonScheduleFields.ShippingWindowEnd, 1, "ShippingWindowEnd");
        orderFields.DefineField(CustomerSalesOrderFields.CustomerSalesOrderId, 2, "CustomerSalesOrderId");
        orderFields.DefineField(CustomerFields.Name, 3, "CustomerName");
        orderFields.DefineField(CustomerSalesOrderFields.ContactName, 4, "ContactName");
        orderFields.DefineField(CustomerSalesOrderFields.OrderDate, 5, "OrderDate");
        orderFields.DefineField(CustomerSalesOrderFields.OrderStatus, 6, "OrderStatus");

    
        // ------------------------------------------------------------------------------------//
        // This block is all for the subselect that counts the qty for this product on 
        // these orders
        IRelationCollection subSelectRelations = new RelationCollection();
        subSelectRelations.Add(CustomerSalesOrderEntity.Relations.CustomerSalesOrderPartEntityUsingCustomerSalesOrderId, "Sub", "", JoinHint.Left);
        subSelectRelations.Add(CustomerSalesOrderPartEntity.Relations.CustomerSalesOrderItemEntityUsingCustomerSalesOrderPartId);

        IPredicateExpression countExpOr = new PredicateExpression();
        countExpOr.Add(CustomerSalesOrderItemFields.ItemStatus == "Confirmed");
        countExpOr.AddWithOr(CustomerSalesOrderItemFields.ItemStatus == "Ordered");

        IPredicateExpression orderFilter = new PredicateExpression();
        orderFilter.Add(CustomerSalesOrderFields.CustomerSalesOrderId.SetObjectAlias("Sub") == CustomerSalesOrderFields.CustomerSalesOrderId);
        orderFilter.AddWithAnd(countExpOr);

        orderFields.DefineField(new EntityField("OrderTotal",
                  new ScalarQueryExpression(CustomerSalesOrderItemFields.AmountCharged.SetAggregateFunction(AggregateFunction.Sum),
                      orderFilter, subSelectRelations)), 7);
        // ------------------------------------------------------------------------------------//

        IRelationCollection orderRelations = new RelationCollection();
        orderRelations.Add(CustomerSalesOrderEntity.Relations.PreSeasonScheduleEntityUsingPreSeasonScheduleId);
        orderRelations.Add(CustomerSalesOrderEntity.Relations.CustomerEntityUsingCustomerId);

        IPredicateExpression pendingOrdersFilter = new PredicateExpression();

        if (orderId > 0)
        {
            pendingOrdersFilter.Add(CustomerSalesOrderFields.CustomerSalesOrderId == orderId);
        }

        if (orderStatus!= "" && orderStatus != "All" && orderId == 0)
        {
            pendingOrdersFilter.AddWithAnd(CustomerSalesOrderFields.OrderStatus == orderStatus);
        }
        
        if (customerId > 0 && orderId == 0)
        {
            pendingOrdersFilter.AddWithAnd(CustomerSalesOrderFields.CustomerId == customerId);
        }

        ISortExpression orderSort = new SortExpression();
        if(sortOn == "OrderTotal")
        {
            orderSort.Add(orderFields[7] | SortDirection.Ascending);
        }
        orderSort.Add(PreSeasonScheduleFields.ShippingWindowEnd |  SortOperator.Ascending);

        DataTable dtOrders = new DataTable();
        TypedListDAO dao = new TypedListDAO();
        dao.GetMultiAsDataTable(orderFields, dtOrders, 0, orderSort, pendingOrdersFilter, orderRelations, true, null, null, 0, 0);

        Int32 OrderCount = dtOrders.Rows.Count;
        if (OrderCount == 0)
        {
            lblGridMsg.Text = "No <b>" + orderStatus + " </b>orders were found.";
        }
        else
        {
            lblGridMsg.Text = "";
        }
        
        gvPendingOrders.DataSource = dtOrders;
        gvPendingOrders.DataBind();
    }


Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-Jul-2009 10:29:14   

I'm sorry, you should use SortOperator enum not the ASP.NET SotDirection

        ISortExpression orderSort = new SortExpression();
        if(sortOn == "OrderTotal")
        {
            orderSort.Add(orderFields[7] | SortOperator.Ascending);
        }
rtbike
User
Posts: 23
Joined: 23-Jan-2009
# Posted on: 30-Jul-2009 21:57:20   

Hi Walaa,

That did not seem to solve the problem. I still get the same error message as I posted above except it chokes on SortOperator instead of SortDirection?

What other way can I approach this?

Thanks,

Todd

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 30-Jul-2009 23:22:25   

Please can you let us know which versions of the following you are using ?

LLBLGen Visual Studio .Net runtime

Thanks

Matt

rtbike
User
Posts: 23
Joined: 23-Jan-2009
# Posted on: 30-Jul-2009 23:33:50   

VS 2008 LLBL Gen 2.6 SelfService Target Frame Work 3.5

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-Jul-2009 07:35:53   

Hi there,

Do this:

orderSort.Add(new SortClause(orderFields[7], SortDirection.Ascending));
David Elizondo | LLBLGen Support Team
rtbike
User
Posts: 23
Joined: 23-Jan-2009
# Posted on: 31-Jul-2009 22:05:59   

Thanks that did the trick, I just needed to use sortOperator



 orderSort.Add(new SortClause(orderFields[7], SortOperator.Descending));