locked
Issue in Service Operations RRS feed

  • Question

  • One issue I am facing in ADO.Net Data Services:
    I created a new ServiceOperation called RecentContents
    The business logic says I need to return records in descending order by Date.

    so the following statement has been written in Service Operation

    [WebGet]
    public IQueryable<Content> RecentContent()
    {
                var result =
            from c in this.CurrentDataSource.ContentSet
            orderby c.LastUpdatedDate descending

            select c;
                return result;

    }


    This works fine when I get all the Contents. It gives me Contents by descending Order.

    But the problem comes when I want to retrieve Top 5 Recent Contents. The query starts returning the results in Ascending Order.
    I used the following statement:

    http://localhost:49701/ContentProviderService.svc/RecentContent?$skip=0&$top=5

    Could you please explain how to resolve this issue.

    Thanks,
    Ashwani
    Monday, September 21, 2009 5:11 AM

Answers

  • Thanks.

    I think I understand correctly.
    We need to provide Order by Clause first . But what I was doing here is passing the skip operations and then within the method order that by Date.


    I made the change in the Service Operation and now works correctly.

    Thanks,
    Ashwani
    Wednesday, September 30, 2009 6:30 AM

All replies

  • Hi Ashwani,

    We need to do the explicit ordering as we dont know if the ServiceOperation is opaque to the Data Services runtime.
    Give that you asked for the top 5 results , if we dont order the results by some mechanism , we wont be able to give you the next 5 results correctly.

    You should inject the Orderby expression in the URI :

    http://localhost:49701/ContentProviderService.svc/RecentContent?$skip=0&$top=5&orderby = LastUpdatedDate desc


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Monday, September 21, 2009 4:15 PM
    Moderator
  • Thanks.

    I think I understand correctly.
    We need to provide Order by Clause first . But what I was doing here is passing the skip operations and then within the method order that by Date.


    I made the change in the Service Operation and now works correctly.

    Thanks,
    Ashwani
    Wednesday, September 30, 2009 6:30 AM