Ejemplo n.º 1
0
 public BulkOptions(int? batchSize = null, int? bulkCopyTimeout = null, SqlBulkCopyOptions sqlBulkCopyOptions = SqlBulkCopyOptions.Default,
   FieldsSelector fieldsSelector = FieldsSelector.Source, bool? caseSensitive = null, bool? enableStreaming = null,
   bool createTable = false, ColumnDefinitionOptions columnDefinitionOptions = null, bool? ignoreDataReaderSchemaTable = null,
   bool? checkTableIfNotExistsBeforeCreation = null)
 {
     this.BatchSize = batchSize;
     this.BulkCopyTimeout = bulkCopyTimeout;
     this.SqlBulkCopyOptions = sqlBulkCopyOptions;
     this.FieldsSelector = fieldsSelector;
     this.CaseSensitive = caseSensitive;
     this.EnableStreaming = enableStreaming;
     this.CreateTable = createTable;
     this.ColumnDefinitionOptions = columnDefinitionOptions;
     this.IgnoreDataReaderSchemaTable = ignoreDataReaderSchemaTable;
     this.CheckTableIfNotExistsBeforeCreation = checkTableIfNotExistsBeforeCreation;
 }
Ejemplo n.º 2
0
        public static ColumnDefinition FromFieldType(Type type, string name, ColumnDefinitionOptions options = null)
        {
            var opt = options ?? ColumnDefinitionOptions.Default;
            bool isPrimaryKey = opt.PrimaryKey?.Select(x => x.ToLowerInvariant()).Contains(name.ToLowerInvariant()) ?? false;

            if (type.Equals(typeof(bool)))
            {
                return new ColumnDefinition(name, "bit", isPrimaryKey, 0, 0, 0, false);
            }
            else if (type.Equals(typeof(bool?)))
            {
                return new ColumnDefinition(name, "bit", isPrimaryKey, 0, 0, 0, true);
            }
            if (type.Equals(typeof(byte)))
            {
                return new ColumnDefinition(name, "tinyint", isPrimaryKey, 0, 0, 0, false);
            }
            else if (type.Equals(typeof(byte?)))
            {
                return new ColumnDefinition(name, "tinyint", isPrimaryKey, 0, 0, 0, true);
            }
            if (type.Equals(typeof(short)))
            {
                return new ColumnDefinition(name, "smallint", isPrimaryKey, 0, 0, 0, false);
            }
            else if (type.Equals(typeof(short?)))
            {
                return new ColumnDefinition(name, "smallint", isPrimaryKey, 0, 0, 0, true);
            }
            if (type.Equals(typeof(int)))
            {
                return new ColumnDefinition(name, "int", isPrimaryKey, 0, 0, 0, false);
            }
            else if (type.Equals(typeof(int?)))
            {
                return new ColumnDefinition(name, "int", isPrimaryKey, 0, 0, 0, true);
            }
            if (type.Equals(typeof(long)))
            {
                return new ColumnDefinition(name, "bigint", isPrimaryKey, 0, 0, 0, false);
            }
            else if (type.Equals(typeof(long?)))
            {
                return new ColumnDefinition(name, "bigint", isPrimaryKey, 0, 0, 0, true);
            }
            if (type.Equals(typeof(float)))
            {
                return new ColumnDefinition(name, "real", isPrimaryKey, 0, 0, 0, false);
            }
            else if (type.Equals(typeof(float?)))
            {
                return new ColumnDefinition(name, "real", isPrimaryKey, 0, 0, 0, true);
            }
            if (type.Equals(typeof(double)))
            {
                return new ColumnDefinition(name, "float", isPrimaryKey, 0, 0, 0, false);
            }
            else if (type.Equals(typeof(double?)))
            {
                return new ColumnDefinition(name, "float", isPrimaryKey, 0, 0, 0, true);
            }
            if (type.Equals(typeof(decimal)))
            {
                return new ColumnDefinition(name, "decimal", isPrimaryKey, 0, opt.Precision, opt.Scale, false);
            }
            else if (type.Equals(typeof(decimal?)))
            {
                return new ColumnDefinition(name, "decimal", isPrimaryKey, 0, opt.Precision, opt.Scale, true);
            }
            if (type.Equals(typeof(Guid)))
            {
                return new ColumnDefinition(name, "uniqueidentifier", isPrimaryKey, 0, 0, 0, false);
            }
            else if (type.Equals(typeof(Guid?)))
            {
                return new ColumnDefinition(name, "uniqueidentifier", isPrimaryKey, 0, 0, 0, true);
            }
            if (type.Equals(typeof(DateTime)))
            {
                return new ColumnDefinition(name, "datetime2", isPrimaryKey, 0, 0, opt.DateTimeScale, false);
            }
            else if (type.Equals(typeof(DateTime?)))
            {
                return new ColumnDefinition(name, "datetime2", isPrimaryKey, 0, 0, opt.DateTimeScale, true);
            }
            if (type.Equals(typeof(string)))
            {
                return new ColumnDefinition(name, "nvarchar", isPrimaryKey, opt.StringMaxLength, 0, 0, true);
            }
            if (type.Equals(typeof(byte[])))
            {
                return new ColumnDefinition(name, "varbinary", isPrimaryKey, opt.BytesMaxLength, 0, 0, true);
            }

            if (opt.ThrowIfUnsupportedType)
            {
                throw new ArgumentOutOfRangeException(nameof(type), type, "Unsupported type");
            }

            return null;
        }
Ejemplo n.º 3
0
 public ImportOptions(int? commandTimeoutSeconds = null, int? batchSize = null, int? bulkCopyTimeout = null, SqlBulkCopyOptions sqlBulkCopyOptions = SqlBulkCopyOptions.Default,
   FieldsSelector fieldsSelector = FieldsSelector.Source, bool? caseSensitive = null, bool? enableStreaming = null,
   bool createTable = false, ColumnDefinitionOptions columnDefinitionOptions = null, bool? ignoreDataReaderSchemaTable = null,
   bool? checkTableIfNotExistsBeforeCreation = null)
   : this(new QueryOptions(commandTimeoutSeconds), new BulkOptions(batchSize, bulkCopyTimeout, sqlBulkCopyOptions, fieldsSelector, caseSensitive,
       enableStreaming, createTable, columnDefinitionOptions, ignoreDataReaderSchemaTable, checkTableIfNotExistsBeforeCreation))
 {
 }