protected virtual Expression VisitMemberAccess(MemberExpression m, StringBuilder sb, QueryParameter data = null) { if (m.Expression == null) { this.VisitConstant(Expression.Constant(Expression.Lambda(m).Compile().DynamicInvoke(null)), sb, data); return(m); } switch (m.Expression.NodeType) { case ExpressionType.Parameter: sb.Append(DataMapper.EscapeName(DataMapper.GetColumnName(typeof(T), m.Member.Name))); break; case ExpressionType.Constant: if (m.Member.MemberType == MemberTypes.Field) { AddParameter(sb, m.Member.Name, ((FieldInfo)m.Member).GetValue(((ConstantExpression)m.Expression).Value), ((FieldInfo)m.Member).FieldType, data); } else { AddParameter(sb, m.Member.Name, ((PropertyInfo)m.Member).GetValue(((ConstantExpression)m.Expression).Value), ((PropertyInfo)m.Member).PropertyType, data); } break; case ExpressionType.MemberAccess: this.VisitConstant(Expression.Constant(Expression.Lambda(m).Compile().DynamicInvoke(null)), sb, data); break; default: throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name)); } return(m); }
public QueryBuilder <T> OrderBy <TKey>(Expression <Func <T, TKey> > keySelector) { if (this.OrderByStr.Length > 0) { this.OrderByStr.Append(", "); } this.OrderByStr.Append(DataMapper.EscapeName(DataMapper.GetColumnName(typeof(T), ((MemberExpression)keySelector.Body).Member.Name))); return(this); }
public virtual QueryBuilder <T> Update(string propertyName, object value) { this.isUpdate = true; if (this.UpdateStr.Length > 0) { this.UpdateStr.Append(", "); } this.UpdateStr.Append(String.Format("{0} = ", DataMapper.EscapeName(DataMapper.GetColumnName(typeof(T), propertyName)))); this.AddParameter(this.UpdateStr, null, value, value.GetType()); return(this); }
public virtual QueryBuilder <T> Update <TKey>(string propertyName, Expression <Func <T, TKey> > expr) { this.isUpdate = true; if (this.UpdateStr.Length > 0) { this.UpdateStr.Append(", "); } this.UpdateStr.Append(String.Format("{0} = ", DataMapper.EscapeName(DataMapper.GetColumnName(typeof(T), propertyName)))); this.Visit(expr, this.UpdateStr); return(this); }
public virtual QueryBuilder <T> Increment <TKey>(Expression <Func <T, TKey> > keySelector, object amount) { this.isUpdate = true; if (this.UpdateStr.Length > 0) { this.UpdateStr.Append(", "); } this.UpdateStr.Append(String.Format("{0} = {0} + ", DataMapper.EscapeName(DataMapper.GetColumnName(typeof(T), ((MemberExpression)keySelector.Body).Member.Name)))); this.AddParameter(this.UpdateStr, null, amount, amount.GetType()); return(this); }