/// <summary> /// 指定字段名自减并返回当前语句 /// </summary> /// <typeparam name="T">实体类类型</typeparam> /// <param name="cmd">更新语句</param> /// <param name="expr">实体类属性</param> /// <exception cref="ExpressionInvalidException">表达式不正确</exception> /// <exception cref="NullAttributeException">没有设置特性</exception> /// <returns>当前语句</returns> /// <example> /// <code lang="C#"> /// <![CDATA[ /// public class UserRepository : DatabaseTable<User> /// { /// //other necessary code /// /// public Boolean UpdateEntity(User user) /// { /// return this.Update() /// .Decrease<User>(c => c.LoginTimes) /// .Where<User>(c => c.UserID == user.UserID) /// .Result() > 0; /// /// //UPDATE tbl_Users SET LoginTimes = LoginTimes - 1 WHERE UserID = @UserID /// //@UserID = user.UserID /// } /// } /// ]]> /// </code> /// </example> public static UpdateCommand Decrease <T>(this UpdateCommand cmd, Expression <Func <T, Object> > expr) { MemberExpression left = ExpressionHelper.GetMemberExpression(expr.Body); if (left == null) { throw new ExpressionInvalidException(); } DatabaseColumnAttribute attr = ExpressionHelper.GetColumnAttribute(cmd, left); if (attr == null) { throw new NullAttributeException(); } return(cmd.Decrease(attr.ColumnName)); }