locked
Sorting BusinessEntityCollection RRS feed

  • Question

  • Hi,

    could anybody would give me sample code which would sort BusinessEntityCollection by specified parameter, for example fullname of systemuser enitities?

    Thanks a lot

    Chevie
    Saturday, November 21, 2009 5:23 PM

Answers

  • you need to use OrderExpression to sort the return result...

    following is example from SDK which retrives account sorted based on address1_city,address1_county..

    hope this helps..

    // For example, you can sort the accountnumber attribute in descending order, 
    and the address1_city attribute in ascending order. ///The following example demonstrates how to use the
    //QueryByAttribute.Orders property. // Create the QueryByAttribute object. QueryByAttribute query = new QueryByAttribute(); query.ColumnSet = new AllColumns(); query.EntityName = EntityName.account.ToString(); // Set the order of returned accounts. OrderExpression oe = new OrderExpression(); oe.AttributeName = "address1_city"; oe.OrderType = OrderType.Ascending; OrderExpression oe1 = new OrderExpression(); oe1.AttributeName = "address1_county"; oe1.OrderType = OrderType.Ascending; query.Orders = new OrderExpression[]{oe, oe1};
    Saturday, November 21, 2009 6:59 PM

All replies

  • you need to use OrderExpression to sort the return result...

    following is example from SDK which retrives account sorted based on address1_city,address1_county..

    hope this helps..

    // For example, you can sort the accountnumber attribute in descending order, 
    and the address1_city attribute in ascending order. ///The following example demonstrates how to use the
    //QueryByAttribute.Orders property. // Create the QueryByAttribute object. QueryByAttribute query = new QueryByAttribute(); query.ColumnSet = new AllColumns(); query.EntityName = EntityName.account.ToString(); // Set the order of returned accounts. OrderExpression oe = new OrderExpression(); oe.AttributeName = "address1_city"; oe.OrderType = OrderType.Ascending; OrderExpression oe1 = new OrderExpression(); oe1.AttributeName = "address1_county"; oe1.OrderType = OrderType.Ascending; query.Orders = new OrderExpression[]{oe, oe1};
    Saturday, November 21, 2009 6:59 PM
  • Thanks a lot, that helped. I only had to change

    query.Orders = new OrderExpression[]{oe, oe1};

    to

    query.Orders.Add(oe);
    query.Orders.Add(oe2);

    Thanks a lot!!!
    Monday, November 23, 2009 11:33 AM