Can GraphDiff be used for partial updates of simple entities too? c# entity-framework graphdiff


A WebApi2 project I'm working on uses EF6 CodeFirst. Additionally, I'm mapping between my models and dtos using AutoMapper. I don't employ OData.

In order to handle entity updates, I'm looking for a solution. I can't use Delta and I don't want to use JsonPatch because I don't utilize OData.

My scenario is

  1. Data is sent from the client to the server (as dto).
  2. Using EF, the server loads the related entity and entity graph from the database.
  3. The entity should be patched by the server with the dto values.
  4. The patched entity is saved by the server, and EF should handle change tracking.

My issue is with number 3.

Can I patch entities using GraphDiff? (I'll use GraphDiff as well; I was updating complex graphs.) And will EF change tracking begin automatically if I can use GraphDiff?

1/27/2015 1:55:39 PM

Accepted Answer

In the scenario given above:

  1. as mentioned earlier
  2. Server converts the dto to the model and passes the model to the service or repository.
  3. Before updating, Graphdiff loads the model and handles any modified properties appropriately.
  4. The revised object will be returned by Graphdiff.

As for (3):

A per-property patch is not performed by GraphDiff. It traverses the entire object, creates a diff, and then merges the modifications. It is then up to EF to submit the appropriate SQL statements after tracking the loaded graph with EF.

7/21/2016 4:52:07 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow