接口类:
/// <summary> /// 更新指定字段 /// </summary> /// <param name="entity">实体</param> /// <param name="fileds">更新字段数组</param> void UpdateEntityFields(T entity, List<string> fileds);
实现接口类:
public void UpdateEntityFields(T entity, List<string> fileds) { if (entity != null&&fileds!=null) { dbContext.CreateObjectSet<T>().Attach(entity); var SetEntry = ((IObjectContextAdapter)dbContext).ObjectContext. ObjectStateManager.GetObjectStateEntry(entity); foreach (var t in fileds) { SetEntry.SetModifiedProperty(t); } } }