locked
Expand and orderby RRS feed

  • Question

  • Combo orderby does not seem to work when you have an Expand.  Is this by design?  Is there a workaround? tia

     

    var q = (from ee in db.Entries.Expand("Users")

    where e.IsPrivate==false

    orderby e.IsSticky descending, e.Created descending

    select e).Take(10).ToList();

    Tuesday, November 4, 2008 6:25 PM

Answers

  • Looks like a bug.  I am able to repro this.  Looks like the second Property in the orderby operation is causing problems.

     

    The work around is to call Expand after calling orderby:

     

    var q = (((DataServiceQuery<User>)(from ee in db.Entries

    where e.IsPrivate==false

    orderby e.IsSticky descending, e.Created descending

    select e)).Expand("Users").Take(10).ToList();

     

     

    Tuesday, November 4, 2008 8:41 PM
    Moderator

All replies

  • What is the error?  What is the URI generated by Linq to ADO.NET Data Services?

     

    Tuesday, November 4, 2008 7:00 PM
    Moderator
  • Thanks Andrew.  q.ToString() with throw error on query even before I can run it so I can't see the generated query string. But the error is:

     

    Expression of type 'System.Data.Services.Client.DataServiceQuery`1[SocialRestClient.ServiceReference1.Entries]' cannot be used for parameter of type 'System.Linq.IOrderedQueryable`1[SocialRestClient.ServiceReference1.Entries]' of method 'System.Linq.IOrderedQueryable`1[SocialRestClient.ServiceReference1.Entries] ThenByDescending[Entries,DateTime](System.Linq.IOrderedQueryable`1[SocialRestClient.ServiceReference1.Entries], System.Linq.Expressions.Expression`1[System.Func`2[SocialRestClient.ServiceReference1.Entries,System.DateTime]])'

     

    If I remove the Expand("Users"), it works.  If I remove the last orderby, it works. 

    Tuesday, November 4, 2008 7:13 PM
  • Looks like a bug.  I am able to repro this.  Looks like the second Property in the orderby operation is causing problems.

     

    The work around is to call Expand after calling orderby:

     

    var q = (((DataServiceQuery<User>)(from ee in db.Entries

    where e.IsPrivate==false

    orderby e.IsSticky descending, e.Created descending

    select e)).Expand("Users").Take(10).ToList();

     

     

    Tuesday, November 4, 2008 8:41 PM
    Moderator
  • ah.  Thank you Andrew.

    Tuesday, November 4, 2008 10:32 PM