public SqlProvider <T> FormatUpdateZhanglei <TKey>(Expression <Func <T, TKey> > expression, TKey value) { MemberExpression m = expression.Body as MemberExpression; if (m == null) { var mbs = new ExpressionPropertyFinder(expression, typeof(T)).MemberList; if (!mbs.Any()) { throw new FieldAccessException($"未在更新表达式中找到类型 {typeof(T).Name} 的任何字段"); } } var update = ResolveExpression.Instance(Dialect).ResolveUpdateZhanglei <T>(expression, value); var where = ResolveExpression.Instance(Dialect).ResolveWhere(Context.CommandSet.WhereExpression); var whereSql = where.SqlCmd; Params = where.Param; Params.AddDynamicParams(update.Param); SqlString = $"UPDATE {FormatTableName(false)} {update.SqlCmd} {whereSql}"; return(this); }
public SqlProvider <T> FormatUpdateNotDefault(T entity) { var update = ResolveExpression.Instance(Dialect).ResolveUpdateNotDefault <T>(a => entity); var where = ResolveExpression.Instance(Dialect).ResolveWhere(entity); var whereSql = where.SqlCmd; Params = where.Param; Params.AddDynamicParams(update.Param); SqlString = $"UPDATE {FormatTableName(false)} {update.SqlCmd} {whereSql}"; return(this); }
public SqlProvider <T> FormatUpdate(Expression <Func <T, T> > updateExpression) { var update = ResolveExpression.Instance(Dialect).ResolveUpdate(updateExpression); var where = ResolveExpression.Instance(Dialect).ResolveWhere(Context.CommandSet.WhereExpression); var whereSql = where.SqlCmd; Params = where.Param; Params.AddDynamicParams(update.Param); SqlString = $"UPDATE {FormatTableName(false)} {update.SqlCmd} {whereSql}"; return(this); }
public SqlProvider <T> FormatUpdateSelect(Expression <Func <T, T> > updator) { var update = ResolveExpression.Instance(Dialect).ResolveUpdate(updator); var selectSql = ResolveExpression.Instance(Dialect).ResolveSelectOfUpdate(typeof(T).GetPropertiesInDb(true), Context.QuerySet.SelectExpression); var where = ResolveExpression.Instance(Dialect).ResolveWhere(Context.QuerySet.WhereExpression); var whereSql = where.SqlCmd; Params = where.Param; Params.AddDynamicParams(update.Param); var topSql = Context.QuerySet.TopNum.HasValue && !Dialect.IsUseLimitInsteadOfTop ? " TOP " + Context.QuerySet.TopNum.Value : ""; var limitSql = Context.QuerySet.TopNum.HasValue && Dialect.IsUseLimitInsteadOfTop ? $" Limit {Context.QuerySet.TopNum.Value}" : ""; SqlString = $"UPDATE {topSql} {FormatTableName(false)} WITH ( UPDLOCK, READPAST ) {update.SqlCmd} {selectSql} {whereSql} {limitSql}"; return(this); }
public SqlProvider <T> FormatUpdateZhanglei(T entity, IEnumerable <LambdaExpression> expressionList) { var update = ResolveExpression.Instance(Dialect).ResolveUpdateZhanglei <T>(expressionList, entity); IWhereExpression where; if (Context.CommandSet.WhereExpression == null) { where = ResolveExpression.Instance(Dialect).ResolveWhere(entity); } else { where = ResolveExpression.Instance(Dialect).ResolveWhere(Context.CommandSet.WhereExpression); } var whereSql = where.SqlCmd; Params = where.Param; Params.AddDynamicParams(update.Param); SqlString = $"UPDATE {FormatTableName(false)} {update.SqlCmd} {whereSql}"; return(this); }