标签:
解决方案
/// <summary>
/// 保存
/// </summary>
/// <param name="g"></param>
public static void DbSave(GROUP g)
{
if (g == null)
{
return;
}
if (YJdb.Entry(g).State == EntityState.Detached)
{
var set = YJdb.Set<GROUP>();
GROUP attachedProduct = set.Local.SingleOrDefault(p => p.ID == g.ID);
//如果已经被上下文追踪
if (attachedProduct != null)
{
var attachedEntry = YJdb.Entry(attachedProduct);
attachedEntry.CurrentValues.SetValues(g);
}
else //如果不在当前上下文追踪
{
YJdb.Entry(g).State = EntityState.Modified;
}
}
YJdb.SaveChanges();
}
EF ASP.NET MVC 更新出错:ObjectStateManager中已存在具有同一键的对象
标签:
原文地址:http://www.cnblogs.com/louby/p/4869854.html