web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to write orderby clause using linq query and also using queryexpression class.

(0) ShareShare
ReportReport
Posted on by 6

Hi All,

   I am having the trouble in below lines of code 

var res = (from c in orgContext.CreateQuery("contact")
join a in orgContext.CreateQuery("annotation") on c["contactid"] equals a["objectid"]
where (bool)a["isdocument"] == true && (int)a["objecttypecode"] == GetObjectTypeCode("contact")
orderby(a["createdon"]) descending
select new
{
GUID = c["contactid"],
FirstName=c["firstname"]
}).Take(5).Distinct();

I have use the orderby clause here showing as above , But it's throwing an error.

Can anybody help me , how to resolve this issue.

and also i want to use the oderby in queryexpression class in c# application. 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Try changing it to to orderby a["createdon"]

    - no brackets or space

    What is the error that is being thrown?

    The QueryExpresion has an Orders property - see msdn.microsoft.com/.../microsoft.xrm.sdk.query.queryexpression.orders.aspx

    Hope this helps,

    Scott

  • Suggested answer
    Hamzeh Zawahreh Profile Picture
    3,674 on at

    Hi check this link

    msdn.microsoft.com/.../gg309256.aspx

  • EmployeeOcta Profile Picture
    6 on at

    Hi Scott Durow ,

    I have tried with  the your suggestion but it's still throwing the same error.

    An unhandled exception of type 'System.NotSupportedException' occurred in Microsoft.Xrm.Sdk.dll

    Additional information: The 'orderBy' expression is limited to invoking the 'c' parameter.

    The below is my detail query

    var res = (from c in orgContext.CreateQuery("contact")

                              join a in orgContext.CreateQuery("annotation") on c["contactid"] equals a["objectid"]

                              where (bool)a["isdocument"] == true && (int)a["objecttypecode"] == GetObjectTypeCode("contact")

                              orderby a["createdon"]

                              select new

                              {

                                  GUID = c["contactid"],

                                  FirstName=c["firstname"]

                              }).Take(5).Distinct();

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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans