110,501
社区成员
发帖
与我相关
我的任务
分享
public bool Delete(Sample et)
{
bool rv = true;
try
{//...
ObjectStateEntry oses = null;
bool isfound =((IObjectContextAdapter)_dataContext).ObjectContext.ObjectStateManager.TryGetObjectStateEntry(et, out oses);
if (oses==null)
_dataContext.Samples.Attach(et);
_dataContext.Samples.Remove(et);
_dataContext.Commit();
}
}
catch(Exception e)
{
rv = false;
}
return rv;
}
ObjectStateManager objectStateManager = context.ObjectStateManager;
ObjectStateEntry oses = null;
bool found = _dataContext.ObjectStateManager.TryGetObjectStateEntry(((IEntityWithKey)et).EntityKey, out oses);
if(!found) //从逻辑上讲应该判断这个标识
_dataContext.Samples.Attach(et);
。。。