Esempio n. 1
0
        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(" )");
        }
        protected override Expression VisitMember(MemberExpression node)
        {
            ParameterSyntaxType type;

            if (parameterMappings == null)
            {
                type = ParameterSyntaxType.Argument;
            }
            else
            {
                Expression       parameterNode;
                MemberExpression current = node;
                do
                {
                    parameterNode = current.Expression;
                    current       = parameterNode as MemberExpression;
                } while (current != null);

                type = parameterMappings[parameterNode];
            }

            switch (type)
            {
            case ParameterSyntaxType.None:
                output.Append(quoter.QuoteName(tableMetadata.ColumnMappings[node.Member.Name]));
                break;

            case ParameterSyntaxType.Target:
                output.Append("T.").Append(quoter.QuoteName(tableMetadata.ColumnMappings[node.Member.Name]));
                break;

            case ParameterSyntaxType.Source:
                output.Append("S.").Append(quoter.QuoteName(tableMetadata.GetParameterName(node)));
                break;

            case ParameterSyntaxType.Argument:
                output.AppendFormat("@{0}", tableMetadata.GetParameterName(node));
                break;
            }
            return(node);
        }
Esempio n. 3
0
        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();
        }