using System.Linq.Expressions;

//用表达式树,部分字段
Expression<Func<CourseSchedule, object>>[] updatedProperties = {
p => p.createtime,
             p => p.teacher
};

调用Helper类

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;
}

 

作者:沐雪
文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。