public override void BulkInsert(ITableData data, string tableName) { var TN = new ObjectNameDescriptor(tableName, QB, QE); var sourceColumnNames = data.ColumnMapping.Cast <IColumnMapping>().Select(cm => cm.SourceColumn).ToList(); var destColumnNames = data.ColumnMapping.Cast <IColumnMapping>().Select(cm => cm.DataSetColumn).ToList(); var quotedDestColumns = destColumnNames.Select(col => TN.QB + col + TN.QE); using (var writer = DbConnection.BeginBinaryImport($@" COPY {TN.QuotatedFullName} ({string.Join(", ", quotedDestColumns)}) FROM STDIN (FORMAT BINARY)")) { while (data.Read()) { writer.StartRow(); foreach (var destCol in destColumnNames) { TableColumn colDef = DestinationColumns[destCol]; int ordinal = data.GetOrdinal(destCol); object val = data.GetValue(ordinal); if (val != null) { object convertedVal = System.Convert.ChangeType(data.GetValue(ordinal), colDef.NETDataType); writer.Write(convertedVal, colDef.InternalDataType.ToLower()); } else { writer.WriteNull(); } } } writer.Complete(); } }
protected override void DoBulkInsert(ITableData data) { data.Definition.EnsureColumns(this, true); var TN = new ObjectNameDescriptor(data.Definition.Name, ConnectionManagerType.Postgres); var quotedDestColumns = data.Definition.ColumnsSynchronized.Names().Select(col => TN.QB + col + TN.QE); using (var writer = DbConnection.BeginBinaryImport($@" COPY {TN.QuotatedFullName} ({string.Join(", ", quotedDestColumns)}) FROM STDIN (FORMAT BINARY)")) { foreach (var row in data.EnumerateRowsAndConvertValuesToNETDataType()) { writer.StartRow(); foreach (var column in row) { if (column.value != null) { writer.Write(column.value, column.column.InternalDataType.ToLower()); } else { writer.WriteNull(); } } } writer.Complete(); } }