2

I have a WebApi2 project with EF6 CodeFirst. I'm also using AutoMapper to map between my models and dto's. I'm not using OData.

I'm trying to find a solution to handle updates of entities. As I'm not using OData I can't use Delta and I would not like to use JsonPatch.

In my scenario:

  1. Client sends the data (as dto) to the server
  2. Server loads the associated entity / entity graph from the DB using EF
  3. Server should patch the entity with values of the dto
  4. Server saves the patched entity and EF should take care of change tracking

My problem lies with 3.

Can I use GraphDiff for patching entities? (I will also be using GraphDiff was updating complex graphs). And if I can use GraphDiff, will EF change tracking kick in automatically?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • Did you find anything out? I want to do the same thing. Graphdiff seems to ignore members that are collections and that are input with a null value instead of an empty collection. But if I put in a property value (eg Name = null) it will replace the value with null. – mortb May 04 '15 at 14:31

1 Answers1

2

In the above-mentioned scenario:

  1. As above
  2. Server maps from dto to model and passes model to service/repository
  3. Graphdiff will load the model before updating and will take care of changed properties accordingly
  4. Graphdiff will return the updated entity

As for (3):

GraphDiff does not do a per-property patch. It updates the whole object by traversing it and build a diff and then it merges the changes. As the loaded graph is tracked by EF, it is then EF's task to send the correct SQL statements.

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • -1: For me the answer is not clear. Do you want to say that in Step 3 GraphDiff will "take care of changed properties" like patch with Delta? If yes, then I cannot confirm this for my current situation. Because when I tried to update the graph of an object, all none provided properties were set to "null" if possible (otherwise constraint checks take effect). Therefore I've got the behavior of the "update" method but not "patch" method - what do you say? – LFish Jul 21 '16 at 14:35