Entity framework DbContext update value without query and by foreign key

前端 未结 3 1663
天命终不由人
天命终不由人 2021-01-19 19:08

I have a method for updating some tables. For update I need get first of TestProcess, but I don\'t like that. How can I update TestProcess without

3条回答
  •  轮回少年
    2021-01-19 19:46

    You can do like that (you probably should have all the test process data):

    TestProcess pr = new TestProcess();
    
    pr.Id = id;
    pr.UpdateID = updateID;
    
    context.Attach(pr);
    context.ObjectStateManager.ChangeObjectState(pr, EntityState.Modified);
    context.SaveChanges();
    

提交回复
热议问题