2

Given a database table Person holding the 3 colums Id, Firstname and Lastname.

How does the ASP.NET Core Web API MVC controller methods PATCH (modify only the lastname) look like when using a real DbContext.

I do not know how to implement it at all (and can't find a tutorial on that) so I ended up with the code below but do not know how to procede.

[HttpPatch("{id}")]
public void Patch(int id, [FromBody]Person value) 
{
  //is this the correct method signature?
  // what to do with dbContext in here?
}
5
  • can you share your code ? Commented Sep 16, 2016 at 5:52
  • I implemented that code without clue because I wasn't able to find a tutorial on that topic. So sharing my code is useless since I don't know how to write it at all. I edit the question an remove the dbContext.SaveChanges part. For more information please take a look at: stackoverflow.com/questions/39514203/… Commented Sep 16, 2016 at 5:58
  • 1
    if you need a feedback from the SO community then you have to spend some time with your series of questions and identify the items one by one according to the relevant order.then put those things one at a time.at that time you'll have a solution.otherwise this will be a another question without an answer. pretty sure about that. Commented Sep 16, 2016 at 6:31
  • From the previous question i extracted one snippet. I do not know how to implement that. So I asked how I should implement it. I can not give code I do not know. In the previous question it was suggested to split it up into multiple questions. This question is the first of multiple questions. Feel free to give me more hints I can edit this question so it fits your needs. Commented Sep 16, 2016 at 6:36
  • @Sampath: I added the code where my problem starts. Unfortunatly thats all I have. Commented Sep 16, 2016 at 6:44

2 Answers 2

2

So, PATCH-request, accordingly to the REST guidelines should provide the ability to partially modify the resource with only properties and values given in request. If you are confused about how to project partially changes on your DB - there is a simple answer. Update only those DB-fields, which are affected in PATCH request :).

There are some libraries, available in NuGet, which can help you to implement e PATCH in your API.Take a look at JsonPatch for example. There is a good sample from controller till DB.

UPD: Another one library

Sign up to request clarification or add additional context in comments.

Comments

2

If you have already implemented the client logic you can use SimplePatch (how to use in the link).

Disclaimer: I'm the author of the project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.