EF 只更新部分字段
/// 只更新storedAddress数据中的DefaultAddress字段,更新为false /// 将默认地址改为不是默认地址 /// </summary> /// <param name="id">需要修改的对象的id</param> public void Update(int id) { StoredAddress s = new StoredAddress { StoredAddressID = id }; object originalItem = null; System.Data.EntityKey key = _context.CreateEntityKey("StoredAddresses", s); if (_context.TryGetObjectByKey(key, out originalItem)) { _context.Detach(originalItem); } s.DefaultAddress = true; _context.StoredAddresses.Attach(s); s.DefaultAddress = false; _context.SaveChanges(); _context.Detach(s); }
posted on 2014-11-04 11:20 hardy_Wang 阅读(631) 评论(0) 编辑 收藏 举报