Notifications
Announcements
No record found.
Is there a way to specify a multi-sort either as the query is being built or on the result set outputted by the QueryExpression?
*This post is locked for comments
Have u already tried mutiple .AddOrder on your Query expression?
Or use LINQ for your result and try multiple sort like this link suggest:
stackoverflow.com/.../multiple-order-by-in-linq
If this solves, please Like and mark as "Verified Answer"
Already tried multiple AddOrder methods and that did not work. To use LINQ I'd have to load CRM classes (using Xrm.cs) right?
you add multiple sort orders when using queryexpression
Microsoft.Xrm.Sdk.Query.QueryExpression query = new Microsoft.Xrm.Sdk.Query.QueryExpression();
query.Orders.Add(new Microsoft.Xrm.Sdk.Query.OrderExpression("firstname", Microsoft.Xrm.Sdk.Query.OrderType.Ascending));
query.Orders.Add(new Microsoft.Xrm.Sdk.Query.OrderExpression("lastname", Microsoft.Xrm.Sdk.Query.OrderType.Ascending));
query.Orders.Add(new Microsoft.Xrm.Sdk.Query.OrderExpression("birthdate", Microsoft.Xrm.Sdk.Query.OrderType.Ascending));
also check
msdn.microsoft.com/.../microsoft.xrm.sdk.query.queryexpression.orders.aspx
msdn.microsoft.com/.../microsoft.xrm.sdk.query.queryexpression.addorder.aspx
www.magnetismsolutions.com/.../dynamics_crm_2011_querying_data_with_queryexpression
Thank you for your answer. Is it possible to add an order attribute from a related entity?
For LINQ with early bound, you will need the code generation utility:
msdn.microsoft.com/.../gg327844.aspx
For LINQ with late bound (I haven' tried this method yet):
msdn.microsoft.com/.../gg334415.aspx
or
msdn.microsoft.com/.../Hh210215.aspx
If this became too tricky, maybe you can break your query in two:
Apply the "main order" on the first query, and over the result, apply the second order filter.
This is what you are expecting:
QueryExpression query = new QueryExpression("opportunity") { ColumnSet=new ColumnSet("topic") }; OrderExpression order1 = new OrderExpression("topic", OrderType.Ascending); OrderExpression order2 = new OrderExpression("createdon", OrderType.Descending); query.Orders.Add(order1); query.Orders.Add(order2);
Also, you cannot add order attributes from related entity.
Hi
Related entity adding order by is not possible why don't use fetch xml in plugin?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2