解决方案

/// <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();
}

04-24 20:46