public SqlCodeGeneratorExpressionVisitor(StringBuilder output, Dictionary <Expression, ParameterSyntaxType> parameterMappings, IQueryMetadata tableMetadata, IdentifierQuoter quoter) { this.output = output; this.parameterMappings = parameterMappings; this.tableMetadata = tableMetadata; this.quoter = quoter; }
public static void GenerateWhereClause <TEntity, TParams>(this Expression <PredicateSpecificationDelegate <TEntity, TParams> > predicate, StringBuilder commandText, IdentifierQuoter quoter, IQueryMetadata metadata, ParameterSyntaxType entityParameterType) { var parameterMappings = new Dictionary <Expression, ParameterSyntaxType> { { predicate.Parameters[0], entityParameterType }, { predicate.Parameters[1], ParameterSyntaxType.Argument }, }; new SqlCodeGeneratorExpressionVisitor(commandText, parameterMappings, metadata, quoter).Visit(predicate.Body); }
public static void GenerateUpdateSetList <TEntity, TParams>(this Expression <UpdateSpecificationDelegate <TEntity, TParams> > update, StringBuilder commandText, IdentifierQuoter quoter, IQueryMetadata metadata, ParameterSyntaxType entityParameterType) { new NewObjectExpressionVisitor( n => { commandText.AppendFormat("{0} = ", quoter.QuoteName(metadata.ColumnMappings[n.Member.Name])); new SqlCodeGeneratorExpressionVisitor(commandText, new Dictionary <Expression, ParameterSyntaxType> { { update.Parameters[0], entityParameterType }, { update.Parameters[1], ParameterSyntaxType.Argument }, }, metadata, quoter).Visit(((MemberAssignment)n).Expression); commandText.Append(","); } ).Visit(update); commandText.Length--; // Remove last comma commandText.AppendLine(); }
public static void GenerateInsertValueList <TEntity, TParams>(this Expression <InsertSpecificationDelegate <TEntity, TParams> > insert, StringBuilder commandText, IdentifierQuoter quoter, IQueryMetadata metadata) { // Generate 'values ...' commandText.Append("values ( "); new NewObjectExpressionVisitor( n => { new SqlCodeGeneratorExpressionVisitor(commandText, null, metadata, quoter).Visit(((MemberAssignment)n).Expression); commandText.Append(", "); } ).Visit(insert); commandText.Length -= 2; // Remove last comma commandText.AppendLine(" )"); }
public static void GenerateInsertColumnList <TEntity, TParams>(this Expression <InsertSpecificationDelegate <TEntity, TParams> > insert, StringBuilder commandText, IdentifierQuoter quoter, IQueryMetadata metadata) { // Generate insert values commandText.Append("( "); new NewObjectExpressionVisitor( n => commandText.AppendFormat("{0}, ", quoter.QuoteName(metadata.ColumnMappings[n.Member.Name])) ).Visit(insert); commandText.Length -= 2; // Remove last comma commandText.AppendLine(" )"); }