小编777*_*777的帖子

DbContext 更新与 EntityState 修改

_context.Entry(entity).State = EntityState.ModifiedASP.NET EF Core和之间有什么区别_context.Entity.Update(entity)?例如:

[HttpPut]
public async Task<ActionResult<Student>> PutStudent(Student student)
{
     **_context.Entry(student).State = EntityState.Modified;**
     await _context.SaveChangesAsync();
     return student;
}
Run Code Online (Sandbox Code Playgroud)
    
[HttpPut]
public async Task<ActionResult<Student>> PutStudent(Student student)
{
     **_context.Student.Update(student);**
     await _context.SaveChangesAsync();
     return student;
}
Run Code Online (Sandbox Code Playgroud)

c# http-put dbcontext entity-framework-core asp.net-core

5
推荐指数
1
解决办法
4536
查看次数