protected override SqlBuilder Insert(NewExpression expression, SqlBuilder sqlBuilder) { string columns = " ("; string values = " values ("; for (int i = 0; i < expression.Members.Count; i++) { MemberInfo m = expression.Members[i]; columns += m.Name + ","; ConstantExpression c = expression.Arguments[i] as ConstantExpression; string dbParamName = sqlBuilder.AddDbParameter(c.Value, false); values += dbParamName + ","; } if (columns[columns.Length - 1] == ',') { columns = columns.Remove(columns.Length - 1, 1); } columns += ")"; if (values[values.Length - 1] == ',') { values = values.Remove(values.Length - 1, 1); } values += ")"; sqlBuilder += columns + values; return(sqlBuilder); }
protected override SqlBuilder Update(NewExpression expression, SqlBuilder sqlBuilder) { for (int i = 0; i < expression.Members.Count; i++) { MemberInfo m = expression.Members[i]; ConstantExpression c = expression.Arguments[i] as ConstantExpression; sqlBuilder += m.Name + " ="; sqlBuilder.AddDbParameter(c.Value); sqlBuilder += ","; } if (sqlBuilder[sqlBuilder.Length - 1] == ',') { sqlBuilder.Remove(sqlBuilder.Length - 1, 1); } return(sqlBuilder); }
protected override SqlBuilder Where(MemberExpression expression, SqlBuilder sqlBuilder) { if (expression.Expression.NodeType == ExpressionType.Constant) { object value = GetValue(expression); sqlBuilder.AddDbParameter(value); } else if (expression.Expression.NodeType == ExpressionType.Parameter) { sqlBuilder.SetTableAlias(expression.Member.DeclaringType.Name); string tableAlias = sqlBuilder.GetTableAlias(expression.Member.DeclaringType.Name); if (!string.IsNullOrWhiteSpace(tableAlias)) { tableAlias += "."; } sqlBuilder += " " + tableAlias + expression.Member.Name; } return(sqlBuilder); }
protected override SqlBuilder Where(ConstantExpression expression, SqlBuilder sqlBuilder) { sqlBuilder.AddDbParameter(expression.Value); return(sqlBuilder); }