Ivan-Mark Debono
Ivan-Mark Debono

Reputation: 16310

Can GraphDiff be used for partial updates of simple entities too?

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?

Upvotes: 2

Views: 422

Answers (1)

Ivan-Mark Debono
Ivan-Mark Debono

Reputation: 16310

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.

Upvotes: 2

Related Questions