1 /// <summary>
2 /// Save entity'propertity which is not null
3 /// </summary>
4 /// <typeparam name="T"></typeparam>
5 /// <param name="entity"></param>
6 public void SetModifyColumnsWithOutNull<T>(T entity) where T : EntityObject
7 {
8 ObjectStateEntry stateEntry = null;
9 bool isPresent = _ctx.ObjectStateManager.TryGetObjectStateEntry(entity, out stateEntry);
10 if (stateEntry == null)11 _ctx.AttachTo(typeof(T).Name, entity);12 }
錯誤:An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.說明:我是把上下文放在線程的CallContext里面了,在調用這個方法之前,我查詢過該對象,修改之后,調用這個方法進行更新,結果報上述錯誤。疑問:既然從上下文中獲取不到對象狀態,那附加對象為何還是出錯呢?請大蝦們賜教小弟
- 2 回答
- 0 關注
- 693 瀏覽
添加回答
舉報
0/150
提交
取消