2

I want to send request like this:

/odata.svc/Pages(ItemId=27,PublicationId=1)

Here's the code I'm using:

CdService.ContentDeliveryService cdService = new ContentDeliveryService(new Uri("http://xxx.xx:81/odata.svc"));
var pages = cdService.Pages;
pages = pages.AddQueryOption("ItemId", "270");
pages = pages.AddQueryOption("PublicationId", "2");
var result = pages.Execute();

My problem is that this code is sending request like this:

/odata.svc/Pages()?ItemId=270&PublicationId=2

The problem with this request is that it returns me all the pages there are and not just the one I need.

I could use LINQ:

result.Single(page => page.ItemId == 27 && page.PublicationId == 1);

But the problem is that all the pages will still be sent over the wire

Andrey Marchuk
  • 13,301
  • 2
  • 36
  • 52

3 Answers3

1

You can try this:

EntityDescriptor entityDescriptor = service.Entities.Where(c => 
               c.Entity is CDService.Page 
               && ((CDService.Page)c.Entity).ItemId == pageId.ItemId 
               && ((CDService.Page)c.Entity).PublicationId == pageId.PublicationId)
            .FirstOrDefault();

if (entityDescriptor != null)
{
   return (CDService.Page)entityDescriptor.Entity;
}
Dominic Cronin
  • 6,062
  • 2
  • 23
  • 56
Bappi
  • 918
  • 1
  • 5
  • 9
1

I have found a solution, although not very nice:

ContentDeliveryService cdService1 
                = new ContentDeliveryService(new Uri("http://xxx.xx:81/odata.svc"));
var page = cdService1.Execute<Page>(
             new Uri("http://xxx.xx:81/odata.svc/Pages(ItemId=27,PublicationId=1)"));
Dominic Cronin
  • 6,062
  • 2
  • 23
  • 56
Andrey Marchuk
  • 13,301
  • 2
  • 36
  • 52
1

I've done a quick test with LINQ and it seems to be doing the correct query:

ContentDeliveryService.ContentDeliveryService service = 
    new ContentDeliveryService.ContentDeliveryService(new Uri("http://localhost:99/odata.svc"));
var page = from x in service.Pages
            where x.ItemId == 2122
                    && x.PublicationId == 16
            select x;
foreach (var page1 in page)
{
    Console.WriteLine(page1.Title);
}
Console.Read();
Nuno Linhares
  • 10,214
  • 1
  • 22
  • 42