5

Rather than expose my Database Model I'm trying to get my WebAPI endpoints working with DTO equivalents. In my WebAPIConfig referenced from the Global.asax file I have:

builder.EntitySet<ProductDTO>("Products");
builder.EntitySet<Product>("ProductsDB");

Where Product has an extra field that ProductDTO does not have.

My patch request is currently:

[AcceptVerbs("PATCH", "MERGE")]
public IHttpActionResult Patch([FromODataUri] int key, Delta<ProductDTO> patch)
{

I can see that essentially I need to convert my Delta<ProductDTO> into a Delta<Product> but I cannot see any methods in the Delta class that would allow me to set its underlying EntityType instance.

Does anyone have any advice?

lc.
  • 113,939
  • 20
  • 158
  • 187
user2363071
  • 249
  • 5
  • 16

1 Answers1

0

This question is very similar to yours, please reference it:

Microsoft Odata api through a ViewModel has problems in PATCH

Community
  • 1
  • 1
Tan Jinfu
  • 3,327
  • 1
  • 19
  • 20
  • thank you for your reply. I can see how this example works but it seems that whatever the circumstance, `Delta.GetChangedPropertyNames` returns all of the properties in my DTO whether they have changed or not. Are you able to help? Is this how it works for you? – user2363071 Jul 10 '14 at 15:33
  • I'm not sure whether the above comment referenced you correctly or not so I'll try again here... – user2363071 Jul 10 '14 at 15:40
  • I've realised that Delta.GetChangedPropertyNames contains all of the properies for my DTO because I'm creating the object with my client without extracting it from the service and therefore tracking its context. Thanks. – user2363071 Aug 04 '14 at 15:07