How to Update Existing Disconnected Entity

前端 未结 3 2035
甜味超标
甜味超标 2020-12-21 06:38

I have this code which works in EntityFrameworkCore.

public void SaveProject(Project item)
    {
        var existing = _context.Projects.FirstOrDefault(a =&         


        
3条回答
  •  自闭症患者
    2020-12-21 06:59

    If you are certain that item exist in database, you can use Attach method of DbContext As following

    public void SaveProject(Project item)
    {
        _context.Projects.Attach(item);
        _context.Entity(item).State=EntityState.Modified;
        _context.SaveChanges();
    }
    

提交回复
热议问题