Exemplo n.º 1
0
 public static RelationalTypeMapping GetDefaultMapping(
     [CanBeNull] this IRelationalTypeMapper typeMapper,
     [CanBeNull] object value)
 {
     return(value == null ||
            value == DBNull.Value ||
            typeMapper == null
         ? _nullTypeMapping
         : typeMapper.GetDefaultMapping(value.GetType()));
 }
        protected virtual void Generate(
            [NotNull] CreateSequenceOperation operation,
            [CanBeNull] IModel model,
            [NotNull] SqlBatchBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append("CREATE SEQUENCE ")
            .Append(Sql.DelimitIdentifier(operation.Name, operation.Schema));

            if (operation.ClrType != typeof(long))
            {
                builder
                .Append(" AS ")
                .Append(_typeMapper.GetDefaultMapping(operation.ClrType).DefaultTypeName);
            }

            builder
            .Append(" START WITH ")
            .Append(Sql.GenerateLiteral(operation.StartValue));
            SequenceOptions(operation, model, builder);
        }
Exemplo n.º 3
0
        public virtual void ExecuteSqlCommand([NotNull] string sql, [NotNull] params object[] parameters)
        {
            var commandParameters = new CommandParameter[parameters.Length];
            var substitutions     = new object[parameters.Length];

            for (var index = 0; index < parameters.Length; index++)
            {
                var parameterName = ParameterPrefix + "p" + index;

                var value = parameters[index];

                commandParameters[index] = new CommandParameter(parameterName, value, _typeMapper.GetDefaultMapping(value));

                substitutions[index] = parameterName;
            }

            _statementExecutor.ExecuteNonQuery(
                _connection,
                _connection.Transaction?.DbTransaction,
                new List <SqlBatch> {
                new SqlBatch(
                    string.Format(sql, substitutions),
                    commandParameters)
            });
        }