Exemple #1
0
        internal DbCommand Create(ScopedContext scopedContext, QueryOptions queryOptions, object[] parameters)
        {
            if (scopedContext.ContextProvider != contextProvider)
            {
                throw new ArgumentException($"{nameof(scopedContext.ContextProvider)} presented in received {nameof(ScopedContext)} does not match "
                                            + $"stored in given {nameof(SimpleCommand)}",
                                            nameof(scopedContext));
            }

            var cmd = scopedContext.CreateCommand(CommandText);

            cmd.CommandType = CommandType;

            for (int i = 0; i < parameters.Length; i++)
            {
                if (parameters[i] is DbParameter)
                {
                    cmd.Parameters.Add(parameters[i]);
                }
                else
                {
                    contextProvider.AddParamWithValue(cmd, "@p" + i.ToString(), (object)parameters[i] ?? DBNull.Value);
                }
            }

            contextProvider.ApplyQueryOptions(cmd, scopedContext.PrepareQueryOptions(queryOptions));

            return(cmd);
        }
Exemple #2
0
 protected BulkCopy(ScopedContext context, DbDataReader reader, string destinationTable, BulkOptions bulkOptions, params string[] fields)
 {
     this.context          = context;
     this.bulkOptions      = bulkOptions;
     this.destinationTable = destinationTable;
     this.reader           = reader;
     this.fields           = fields;
 }
Exemple #3
0
        internal DbCommand Create(ScopedContext scopedContext, T value, QueryOptions queryOptions)
        {
            if (scopedContext.ContextProvider != contextProvider)
            {
                throw new ArgumentException($"{nameof(scopedContext.ContextProvider)} presented in received {nameof(ScopedContext)} does not match "
                                            + $"stored in given {nameof(MappedCommand<T>)}",
                                            nameof(scopedContext));
            }

            var cmd = scopedContext.CreateCommand(CommandText);

            cmd.CommandType = CommandType;

            for (int i = 0; i < map.Length; i++)
            {
                var    m = map[i];
                object paramValue;
                if (m.Settings.DetermineNullByValue)
                {
                    var val = m.Settings.Getter(value);
                    paramValue = val == null?contextProvider.GetDbNull(m.Settings.FieldType) : val;
                }
                else
                {
                    paramValue = m.Settings.IsNullGetter(value) ? contextProvider.GetDbNull(m.Settings.FieldType) : m.Settings.Getter(value);
                }

                if (paramValue is DbParameter)
                {
                    cmd.Parameters.Add(paramValue);
                }
                else
                {
                    contextProvider.AddParamWithValue(cmd, m.ParameterName, paramValue);
                }
            }

            contextProvider.ApplyQueryOptions(cmd, scopedContext.PrepareQueryOptions(queryOptions));

            return(cmd);
        }
Exemple #4
0
 internal WrappedCommandWithScope(ScopedContext scopedContext)
 {
     this.scopedContext = scopedContext;
 }
Exemple #5
0
 internal DataReaderAttachedToScopedContext(DbDataReader reader, ScopedContext context)
 {
     this.reader        = reader;
     this.scopedContext = context;
 }
Exemple #6
0
 protected internal abstract BulkCopy GetBulkCopy(ScopedContext context, DbDataReader reader, string destinationTable, BulkOptions bulkOptions, params string[] fields);