我试过这个。我没有遇到错误,我试图让断点跟踪并且它有效,但是在数据库中它没有更新......有什么问题?
SanipexContext db = new SanipexContext();
public ActionResult ProductUpdate()
{
var exist = from e in db.SGRDetails
where e.SGRnumber == sgr && e.product == prodname
select e;
foreach (var s in exist)
{
s.percentage = 20;
}
db.SaveChanges();
}
答案 0 :(得分:0)
您必须使用db上下文附加对象才能使其在数据库中生效:
foreach (var item in exist)
{
s.percentage = 20;
db.Context.SGRDetails.Attach(item )
DbEntityEntry<SGRDetail> entry = db.Entry(item);
entry.Property(e => e.percentage).IsModified = true;
}
db.SaveChanges();