Search code examples
c#linqasp.net-mvc-4odata

Can't get my code for getContinuation working


I am trying to retrieve an entire list of data from an Odata source, but I can't seem to get my getContinuation working... The code I have so far is as follows:

var nwd = new OdataServiceReference.NorthwindEntities(new Uri("http://services.odata.org/Northwind/Northwind.svc/"));

        var res1 = nwd.Orders //response
            .OrderBy(o => o.OrderID)
            .Select(o => new
            {
                o.OrderID,
                o.Customer.CompanyName,
                o.Customer.ContactName,
                o.Employee.FirstName,
                o.Employee.LastName,
                o.Order_Details
            }) as DataServiceQuery;

        var response = (QueryOperationResponse<Order>)
                nwd.Execute<Order>(new Uri(res1.ToString()));

        //var response = res1.Execute() as QueryOperationResponse<OdataServiceReference.Order>;

        var res1List = new List<Order>(response);

        DataServiceQueryContinuation<Order> token;
        while ((token = response.GetContinuation()) != null)
        {
            response = nwd.Execute<Order>(token) as QueryOperationResponse<Order>;
            res1List.AddRange(response);
        }

I am getting the following error:

enter image description here

Any help would be great!


Solution

  • Try replacing the the Order to OdataServiceReference.Order such as Execute<Order> to Execute<OdataServiceReference.Order> and so on to see if that helps.