Exemple #1
0
        public virtual DbCommand Build([NotNull] RelationalConnection connection)
        {
            Check.NotNull(connection, "connection");

            // TODO: Cache command...

            var command = connection.DbConnection.CreateCommand();

            if (connection.Transaction != null)
            {
                command.Transaction = connection.Transaction.DbTransaction;
            }

            var sqlGenerator = _relationalQueryCompilationContext.CreateSqlQueryGenerator();

            command.CommandText = sqlGenerator.GenerateSql(_selectExpression);

            foreach (var commandParameter in sqlGenerator.Parameters)
            {
                var parameter = command.CreateParameter();

                parameter.ParameterName = commandParameter.Name;
                parameter.Value         = commandParameter.Value;

                // TODO: Parameter facets

                command.Parameters.Add(parameter);
            }

            return(command);
        }
Exemple #2
0
        public virtual DbCommand Build(
            [NotNull] IRelationalConnection connection,
            [NotNull] IDictionary <string, object> parameterValues)
        {
            Check.NotNull(connection, nameof(connection));

            // TODO: Cache command...

            var command = connection.DbConnection.CreateCommand();

            if (connection.Transaction != null)
            {
                command.Transaction = connection.Transaction.DbTransaction;
            }

            if (connection.CommandTimeout != null)
            {
                command.CommandTimeout = (int)connection.CommandTimeout;
            }

            var sqlGenerator
                = _relationalQueryCompilationContext.CreateSqlQueryGenerator();

            command.CommandText
                = sqlGenerator.GenerateSql(_selectExpression, parameterValues);

            foreach (var parameterName in sqlGenerator.Parameters)
            {
                var parameter = command.CreateParameter();

                parameter.ParameterName = parameterName;
                parameter.Value         = parameterValues[parameterName];

                // TODO: Parameter facets?

                command.Parameters.Add(parameter);
            }

            return(command);
        }