Answer the question
In order to leave comments, you need to log in
EntityFramework - Partial update of a row in a table?
Good day.
There is a simple table in the database
CREATE TABLE [dbo].[Users]
(
[Id] INT NOT NULL PRIMARY KEY,
[FirstName] VARCHAR(50) NOT NULL,
[LastName] VARCHAR(50) NOT NULL,
[Age] INT NOT NULL
)
[HttpPatch]
public ActionResult Patch([FromBody]User userData)
{
var user = Db.Users.FirstOrDefault(entity => entity.Id== userData.Id);
if (userTokenData == null)
{
return null;
}
user.FirstName = userData.FirstName; // ??
Db.SaveChanges();
return Json(user);
}
{ Id: 1, Age: 42 }
{ Id: 1, FirstName: "Alex", LastName: "Ander" }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question