EntityFramework 更新 整个记录全部字段不确定字段

不确定更新字段,暂时是对全部字段进行更新,原先写的是:

public string Update(A order)

using (Entities ctx = new Entities())
{
//在A表中找到对应原记录
A old=ctx.A.Where(p => p.ID == order.ID).Single();

old=order;

isOK = ctx.SaveChanges();

if (isOK == 1)
{
return "更新成功";
}
else
{
return "更新失败";
}

}

此时isOK = ctx.SaveChanges()为0

参考资料为:http://www.leadnt.com/2012/01/entity-framework-poco-savechanges%E5%A4%B1%E6%95%88%E7%9A%84%E5%8E%9F%E5%9B%A0%E5%8F%8A%E8%A7%A3%E5%86%B3/

最后解决方法是:将old=order;改为ctx.A.ApplyCurrentValues(order);

原文地址:https://www.cnblogs.com/beautifulplanet/p/2650301.html