using System.Linq.Expressions;
//用表达式树,部分字段 Expression<Func<CourseSchedule, object>>[] updatedProperties = { p => p.createtime,
p => p.teacher };
调用Helper类
_courseScheduleRepository.Value.UpdateEntity(schedule, updatedProperties, true);
Helper类
/// <summary> /// 更新部分字段 /// </summary> public virtual int UpdateEntity(T entity, Expression<Func<T, object>>[] updatedProperties, bool IsCommit = true) { int result = 0; _dbContext.Set<T>().Attach(entity); if (updatedProperties.Any()) { foreach (var property in updatedProperties) { _dbContext.Entry<T>(entity).Property(property).IsModified = true; } } if (IsCommit) { result = _UnitOfWork.Commit(); } return result; }