void BulkCopyTest(string context, BulkCopyType bulkCopyType) { using (var conn = new DataConnection(context)) { conn.BeginTransaction(); conn.BulkCopy(new BulkCopyOptions { MaxBatchSize = 50000, BulkCopyType = bulkCopyType }, Enumerable.Range(0, 100000).Select(n => new AllType { ID = 2000 + n, bigintDataType = 3000 + n, smallintDataType = (short)(4000 + n), tinyintDataType = (sbyte)(5000 + n), mediumintDataType = 6000 + n, intDataType = 7000 + n, numericDataType = 8000 + n, decimalDataType = 9000 + n, doubleDataType = 8800 + n, floatDataType = 7700 + n, dateDataType = DateTime.Now, datetimeDataType = DateTime.Now, timestampDataType = null, timeDataType = null, yearDataType = (1000 + n) % 100, year2DataType = (1000 + n) % 100, year4DataType = null, charDataType = 'A', varcharDataType = "", textDataType = "", binaryDataType = null, varbinaryDataType = null, blobDataType = new byte[] { 1, 2, 3 }, bitDataType = null, enumDataType = "Green", setDataType = "one", intUnsignedDataType = (uint)(5000 + n), })); //var list = conn.GetTable<ALLTYPE>().ToList(); conn.GetTable<DB2Test.ALLTYPE>().Delete(p => p.SMALLINTDATATYPE >= 5000); } }
public async Task BulkCopyWithDataContextFromTableAsync( [DataSources(false)] string context, [Values] BulkCopyType copyType) { using (var db = new DataContext(context)) using (var table = db.CreateLocalTable <SimpleBulkCopyTable>()) { await table.BulkCopyAsync(new[] { new SimpleBulkCopyTable() { Id = 1 } }); await table.BulkCopyAsync(5, new[] { new SimpleBulkCopyTable() { Id = 2 } }); await table.BulkCopyAsync(new BulkCopyOptions() { BulkCopyType = copyType }, new[] { new SimpleBulkCopyTable() { Id = 3 } }); await table.BulkCopyAsync(AsyncEnumerableData(10, 1)); await table.BulkCopyAsync(5, AsyncEnumerableData(20, 1)); await table.BulkCopyAsync(new BulkCopyOptions() { BulkCopyType = copyType }, AsyncEnumerableData(30, 1)); } }
void BulkCopyAllTypes(string context, BulkCopyType bulkCopyType) { using (var db = new DataConnection(context)) { db.CommandTimeout = 60; db.GetTable <AllType>().Delete(p => p.ID >= _allTypeses[0].ID); var keepIdentity = bulkCopyType == BulkCopyType.ProviderSpecific && ((InformixDataProvider)db.DataProvider).Adapter.IsIDSProvider; db.BulkCopy( new BulkCopyOptions { BulkCopyType = bulkCopyType, RowsCopiedCallback = copied => Debug.WriteLine(copied.RowsCopied), KeepIdentity = keepIdentity }, _allTypeses); var ids = _allTypeses.Select(at => at.ID).ToArray(); var list = db.GetTable <AllType>().Where(t => ids.Contains(t.ID)).OrderBy(t => t.ID).ToList(); db.GetTable <AllType>().Delete(p => p.ID >= _allTypeses[0].ID); Assert.That(list.Count, Is.EqualTo(_allTypeses.Length)); for (var i = 0; i < list.Count; i++) { CompareObject(db.MappingSchema, list[i], _allTypeses[i]); } } }
private bool Execute(string context, Action perform, bool?keepIdentity, BulkCopyType copyType) { if ((context == ProviderName.Firebird || context == TestProvName.Firebird3) && keepIdentity == true && (copyType == BulkCopyType.Default || copyType == BulkCopyType.MultipleRows || copyType == BulkCopyType.ProviderSpecific)) { var ex = Assert.Catch(() => perform()); Assert.IsInstanceOf <LinqToDBException>(ex); Assert.AreEqual("BulkCopyOptions.KeepIdentity = true is not supported by Firebird provider. If you use generators with triggers, you should disable triggers during BulkCopy execution manually.", ex.Message); return(false); } // RowByRow right now uses DataConnection.Insert which doesn't support identity insert if ((copyType == BulkCopyType.RowByRow || context == ProviderName.Access || context == ProviderName.Informix || (context == ProviderName.SapHana && (copyType == BulkCopyType.MultipleRows || copyType == BulkCopyType.Default))) && keepIdentity == true) { var ex = Assert.Catch(() => perform()); Assert.IsInstanceOf <LinqToDBException>(ex); Assert.AreEqual("BulkCopyOptions.KeepIdentity = true is not supported by BulkCopyType.RowByRow mode", ex.Message); return(false); } perform(); return(true); }
public virtual BulkCopyRowsCopied BulkCopy <T>(BulkCopyType bulkCopyType, ITable <T> table, BulkCopyOptions options, IEnumerable <T> source) { return(bulkCopyType switch { BulkCopyType.MultipleRows => MultipleRowsCopy(table, options, source), BulkCopyType.RowByRow => RowByRowCopy(table, options, source), _ => ProviderSpecificCopy(table, options, source), });
public void BulcopyTPH( [DataSources(false)] string context, [Values] BulkCopyType copyType) { var ms = new MappingSchema(); ms.GetFluentMappingBuilder() .Entity <Inherited3>() .Property(e => e.NullableBool) .HasDataType(DataType.VarChar) .HasLength(1) .HasConversion(b => b.HasValue ? b.Value ? "Y" : "N" : null, s => s != null ? s == "Y" : null, true); var data = new BaseClass[] { new Inherited1 { Id = 1, Value1 = "Str1" }, new Inherited2 { Id = 2, Value2 = "Str2" }, new Inherited3 { Id = 3, Value3 = "Str3", NullableBool = true }, }; using (var db = new DataConnection(context, ms)) using (var table = db.CreateLocalTable <BaseClass>()) { table.BulkCopy(new BulkCopyOptions { BulkCopyType = copyType }, data); var items = table.ToArray(); items[0].Id.Should().Be(1); items[0].Discriminator.Should().Be(1); ((Inherited1)items[0]).Value1.Should().Be("Str1"); items[1].Id.Should().Be(2); items[1].Discriminator.Should().Be(2); ((Inherited2)items[1]).Value2.Should().Be("Str2"); items[2].Id.Should().Be(3); items[2].Discriminator.Should().Be(3); ((Inherited3)items[2]).Value3.Should().Be("Str3"); table.Single(x => x is Inherited1).Should().BeOfType(typeof(Inherited1)); table.Single(x => x is Inherited2).Should().BeOfType(typeof(Inherited2)); table.Single(x => x is Inherited3).Should().BeOfType(typeof(Inherited3)); table.Single(x => ((Inherited1)x).Value1 == "Str1").Should().BeOfType(typeof(Inherited1)); table.Single(x => ((Inherited2)x).Value2 == "Str2").Should().BeOfType(typeof(Inherited2)); table.Single(x => ((Inherited3)x).Value3 == "Str3").Should().BeOfType(typeof(Inherited3)); } }
public virtual BulkCopyRowsCopied BulkCopy <T>(BulkCopyType bulkCopyType, DataConnection dataConnection, BulkCopyOptions options, IEnumerable <T> source) { switch (bulkCopyType) { case BulkCopyType.MultipleRows: return(MultipleRowsCopy(dataConnection, options, source)); case BulkCopyType.RowByRow: return(RowByRowCopy(dataConnection, options, source)); default: return(ProviderSpecificCopy(dataConnection, options, source)); } }
void BulkCopyTest_AccessClient(string context, BulkCopyType bulkCopyType, int maxSize, int batchSize) { using (var conn = new DataConnection(context)) { try { conn.BulkCopy( new BulkCopyOptions { MaxBatchSize = maxSize, BulkCopyType = bulkCopyType, NotifyAfter = 10000, RowsCopiedCallback = copied => Debug.WriteLine(copied.RowsCopied) }, Enumerable.Range(0, batchSize).Select(n => new ALLTYPE { ID = 2000 + n, BIGINTDATATYPE = 3000 + n, INTDATATYPE = 4000 + n, SMALLINTDATATYPE = (short)(5000 + n), DECIMALDATATYPE = 6000 + n, DECFLOAT16DATATYPE = 7000 + n, DECFLOAT34DATATYPE = 7000 + n, REALDATATYPE = 8000 + n, DOUBLEDATATYPE = 9000 + n, CHARDATATYPE = 'A', VARCHARDATATYPE = "", CLOBDATATYPE = "123", DBCLOBDATATYPE = "αβγ", BINARYDATATYPE = new byte[] { 1, 2, 3 }, VARBINARYDATATYPE = new byte[] { 1, 2, 3 }, BLOBDATATYPE = new byte[] { 1, 2, 3 }, GRAPHICDATATYPE = "αβγ", VARGRAPHICDATATYPE = "βγδ", DATEDATATYPE = DateTime.Now.Date, TIMEDATATYPE = TimeSpan.FromSeconds(10), TIMESTAMPDATATYPE = DateTime.Now, XMLDATATYPE = "<root><element strattr=\"strvalue\" intattr=\"12345\"/></root>" })); } catch (Exception e) { Assert.Fail(e.Message); } finally { conn.GetTable <ALLTYPE>().Delete(p => p.DECIMALDATATYPE >= 6000); } } }
public void BulkCopyWithDataContext( [DataSources(false)] string context, [Values] BulkCopyType copyType) { using (var db = new DataContext(context)) using (var table = db.CreateLocalTable <SimpleBulkCopyTable>()) { db.DataProvider.BulkCopy(table, new BulkCopyOptions() { BulkCopyType = copyType }, new[] { new SimpleBulkCopyTable() { Id = 1 } }); } }
public void BulcopyTPHDefault( [IncludeDataSources(false, TestProvName.AllSQLite)] string context, [Values] BulkCopyType copyType) { var data = new BaseDefaultDiscriminator[] { new InheritedDefault1 { Id = 1, Value1 = "Str1" }, new InheritedDefault2 { Id = 2, Value2 = "Str2" }, new InheritedDefault3 { Id = 3, Value3 = "Str3" }, }; using (var db = new DataConnection(context)) using (var table = db.CreateLocalTable <BaseDefaultDiscriminator>()) { table.BulkCopy(new BulkCopyOptions { BulkCopyType = copyType }, data); var items = table.ToArray(); items[0].Id.Should().Be(1); items[0].Discriminator.Should().Be(1); ((InheritedDefault1)items[0]).Value1.Should().Be("Str1"); items[1].Id.Should().Be(2); items[1].Discriminator.Should().Be(2); ((InheritedDefault2)items[1]).Value2.Should().Be("Str2"); items[2].Id.Should().Be(3); items[2].Discriminator.Should().Be(3); ((InheritedDefault3)items[2]).Value3.Should().Be("Str3"); table.Single(x => x is InheritedDefault1).Should().BeOfType(typeof(InheritedDefault1)); table.Single(x => x is InheritedDefault2).Should().BeOfType(typeof(InheritedDefault2)); table.Single(x => x is InheritedDefault3).Should().BeOfType(typeof(InheritedDefault3)); table.Single(x => ((InheritedDefault1)x).Value1 == "Str1").Should().BeOfType(typeof(InheritedDefault1)); table.Single(x => ((InheritedDefault2)x).Value2 == "Str2").Should().BeOfType(typeof(InheritedDefault2)); table.Single(x => ((InheritedDefault3)x).Value3 == "Str3").Should().BeOfType(typeof(InheritedDefault3)); } }
void BulkCopyTest(string context, BulkCopyType bulkCopyType) { using (var conn = new DataConnection(context)) { conn.BeginTransaction(); conn.BulkCopy(new BulkCopyOptions { MaxBatchSize = 50000, BulkCopyType = bulkCopyType }, Enumerable.Range(0, 100000).Select(n => new AllType { ID = 2000 + n, bigintDataType = 3000 + n, smallintDataType = (short)(4000 + n), tinyintDataType = (sbyte)(5000 + n), mediumintDataType = 6000 + n, intDataType = 7000 + n, numericDataType = 8000 + n, decimalDataType = 9000 + n, doubleDataType = 8800 + n, floatDataType = 7700 + n, dateDataType = DateTime.Now, datetimeDataType = DateTime.Now, timestampDataType = null, timeDataType = null, yearDataType = (1000 + n) % 100, year2DataType = (1000 + n) % 100, year4DataType = null, charDataType = 'A', varcharDataType = "", textDataType = "", binaryDataType = null, varbinaryDataType = null, blobDataType = new byte[] { 1, 2, 3 }, bitDataType = null, enumDataType = "Green", setDataType = "one", intUnsignedDataType = (uint)(5000 + n), })); //var list = conn.GetTable<ALLTYPE>().ToList(); conn.GetTable <ALLTYPE>().Delete(p => p.SMALLINTDATATYPE >= 5000); } }
void BulkCopyTest(string context, BulkCopyType bulkCopyType) { using (var conn = new DataConnection(context)) { conn.BeginTransaction(); conn.BulkCopy(new BulkCopyOptions { MaxBatchSize = 50, BulkCopyType = bulkCopyType }, Enumerable.Range(0, 100).Select(n => new AllType { ID = 2000 + n, bigintDataType = 3000 + n, smallintDataType = (short)(4000 + n), decimalDataType = 900000 + n, smalldecimalDataType = 90000 + n, intDataType = 7000 + n, tinyintDataType = (byte)(5000 + n), floatDataType = 7700 + n, realDataType = 7600 + n, dateDataType = DateTime.Now, timeDataType = DateTime.Now - DateTime.Today, seconddateDataType = DateTime.Now, timestampDataType = DateTime.Now, charDataType = 'A', varcharDataType = "AA", textDataType = "text", shorttextDataType = "shorttext", ncharDataType = '\u00fc', nvarcharDataType = "A\u00fcfsdf\u00fc", alphanumDataType = "abcQWE654", binaryDataType = new byte[] { 1 }, varbinaryDataType = new byte[] { 1, 2, 3 }, blobDataType = new byte[] { 1, 2, 3, 4, 5, 6 }, clobDataType = "clobclobclob", nclobDataType = "nclob\u00fcnclob\u00fcnclob\u00fc" })); conn.GetTable <AllType>().Delete(p => p.ID >= 2000); } }
void BulkCopyTest(string context, BulkCopyType bulkCopyType, int maxSize, int batchSize) { using (var conn = new DataConnection(context)) { //conn.BeginTransaction(); conn.BulkCopy( new BulkCopyOptions { MaxBatchSize = maxSize, BulkCopyType = bulkCopyType, NotifyAfter = 10000, RowsCopiedCallback = copied => Debug.WriteLine(copied.RowsCopied) }, Enumerable.Range(0, batchSize).Select(n => new ALLTYPE { ID = 2000 + n, BIGINTDATATYPE = 3000 + n, INTDATATYPE = 4000 + n, SMALLINTDATATYPE = (short)(5000 + n), DECIMALDATATYPE = 6000 + n, DECFLOATDATATYPE = 7000 + n, REALDATATYPE = 8000 + n, DOUBLEDATATYPE = 9000 + n, CHARDATATYPE = 'A', VARCHARDATATYPE = "", CLOBDATATYPE = null, DBCLOBDATATYPE = null, BINARYDATATYPE = null, VARBINARYDATATYPE = null, BLOBDATATYPE = new byte[] { 1, 2, 3 }, GRAPHICDATATYPE = null, DATEDATATYPE = DateTime.Now, TIMEDATATYPE = null, TIMESTAMPDATATYPE = null, XMLDATATYPE = null, })); //var list = conn.GetTable<ALLTYPE>().ToList(); conn.GetTable <ALLTYPE>().Delete(p => p.SMALLINTDATATYPE >= 5000); } }
public async Task BulkCopyWithDataContextAsync( [DataSources(false)] string context, [Values] BulkCopyType copyType) { using (var db = new DataContext(context)) using (var table = db.CreateLocalTable <SimpleBulkCopyTable>()) { await db.DataProvider.BulkCopyAsync(table, new BulkCopyOptions() { BulkCopyType = copyType }, new[] { new SimpleBulkCopyTable() { Id = 1 } }, default); await db.DataProvider.BulkCopyAsync(table, new BulkCopyOptions() { BulkCopyType = copyType }, AsyncEnumerableData(2, 1), default); } }
static void BulkCopyRetrieveSequence(string context, BulkCopyType bulkCopyType) { var data = new[] { new Doctor { Taxonomy = "Neurologist" }, new Doctor { Taxonomy = "Sports Medicine" }, new Doctor { Taxonomy = "Optometrist" }, new Doctor { Taxonomy = "Pediatrics" }, new Doctor { Taxonomy = "Psychiatry" } }; using (var db = new TestDataConnection(context)) { var options = new BulkCopyOptions { MaxBatchSize = 5, //RetrieveSequence = true, KeepIdentity = true, BulkCopyType = bulkCopyType, NotifyAfter = 3, RowsCopiedCallback = copied => Debug.WriteLine(copied.RowsCopied) }; db.BulkCopy(options, data.RetrieveIdentity(db)); foreach (var d in data) { Assert.That(d.PersonID, Is.GreaterThan(0)); } } }
public async Task KeepIdentity_SkipOnInsertTrue( [DataSources(false)] string context, [Values(null, true, false)] bool?keepIdentity, [Values] BulkCopyType copyType, #if NET472 [Values(0, 1)] int asyncMode) // 0 == sync, 1 == async
public static BulkCopyType GetEffectiveType(this BulkCopyType bulkCopyType) => bulkCopyType == BulkCopyType.Default ? DB2iSeriesTools.DefaultBulkCopyType : bulkCopyType;
public void KeepIdentity_SkipOnInsertTrue( [DataSources(false)] string context, [Values(null, true, false)] bool?keepIdentity, [Values] BulkCopyType copyType) { // don't use transactions as some providers will fallback to non-provider-specific implementation then using (var db = new TestDataConnection(context)) using (db.BeginTransaction()) { var lastId = db.InsertWithInt32Identity(new TestTable2()); try { var options = new BulkCopyOptions() { KeepIdentity = keepIdentity, BulkCopyType = copyType }; if (!Execute(context, perform, keepIdentity, copyType)) { return; } var data = db.GetTable <TestTable2>().Where(_ => _.ID > lastId).OrderBy(_ => _.ID).ToArray(); Assert.AreEqual(2, data.Length); // oracle supports identity insert only starting from version 12c, which is not used yet for tests var useGenerated = keepIdentity != true || context == ProviderName.Oracle || context == ProviderName.OracleNative || context == ProviderName.OracleManaged; Assert.AreEqual(lastId + (!useGenerated ? 10 : 1), data[0].ID); Assert.AreEqual(200, data[0].Value); Assert.AreEqual(lastId + (!useGenerated ? 20 : 2), data[1].ID); Assert.AreEqual(300, data[1].Value); void perform() { db.BulkCopy( options, new[] { new TestTable2() { ID = lastId + 10, Value = 200 }, new TestTable2() { ID = lastId + 20, Value = 300 } }); } } finally { // cleanup db.GetTable <TestTable2>().Delete(_ => _.ID >= lastId); } } }
public async Task EnumMappingTestWithTypesAsync([IncludeDataSources(TestProvName.AllPostgreSQL95Plus)] string context, [Values] BulkCopyType bcType) { var mappingSchema = SetupEnums(context, false); var data = new[] { new ScheduleWithTypes { Unit = TimeUnit.Day, UnitNullable = TimeUnit.Day, Amount = 1 }, new ScheduleWithTypes { Unit = TimeUnit.Day, UnitNullable = TimeUnit.Day, Amount = 2 }, new ScheduleWithTypes { Unit = TimeUnit.Day, UnitNullable = TimeUnit.Day, Amount = 3 }, new ScheduleWithTypes { Unit = TimeUnit.Hour, UnitNullable = null, Amount = 1 }, }; var unit = TimeUnit.Day; TimeUnit?unitNullable = TimeUnit.Day; TimeUnit?unitNull = null; using (var db = (DataConnection)GetDataContext(context, mappingSchema)) using (db.CreateLocalTable <ScheduleWithTypes>()) { await db.BulkCopyAsync(new BulkCopyOptions() { BulkCopyType = bcType }, data); db.GetTable <Schedule>().Should().HaveCount(4); db.GetTable <Schedule>().Where(x => x.Unit == unit).Should().HaveCount(3); db.GetTable <Schedule>().Where(x => x.UnitNullable == unit).Should().HaveCount(3); db.GetTable <Schedule>().Where(x => x.UnitNullable == unitNullable).Should().HaveCount(3); db.GetTable <Schedule>().Where(x => x.UnitNullable == TimeUnit.Day).Should().HaveCount(3); db.GetTable <Schedule>().Where(x => x.UnitNullable == unitNull).Should().HaveCount(1); var alItems = db.GetTable <Schedule>().ToArray(); alItems[0].Unit.Should().Be(TimeUnit.Day); alItems[1].Unit.Should().Be(TimeUnit.Day); alItems[2].Unit.Should().Be(TimeUnit.Day); alItems[3].Unit.Should().Be(TimeUnit.Hour); alItems[0].UnitNullable.Should().Be(TimeUnit.Day); alItems[1].UnitNullable.Should().Be(TimeUnit.Day); alItems[2].UnitNullable.Should().Be(TimeUnit.Day); alItems[3].UnitNullable.Should().BeNull(); } }
private async Task <bool> ExecuteAsync(DataConnection db, string context, Func <Task> perform, bool?keepIdentity, BulkCopyType copyType) { if (context.Contains("Firebird") && keepIdentity == true && (copyType == BulkCopyType.Default || copyType == BulkCopyType.MultipleRows || copyType == BulkCopyType.ProviderSpecific)) { var ex = Assert.CatchAsync(async() => await perform()) !; Assert.IsInstanceOf <LinqToDBException>(ex); Assert.AreEqual("BulkCopyOptions.KeepIdentity = true is not supported by Firebird provider. If you use generators with triggers, you should disable triggers during BulkCopy execution manually.", ex.Message); return(false); } bool notSupported = false; if (context.Contains(ProviderName.Informix)) { notSupported = !((InformixDataProvider)db.DataProvider).Adapter.IsIDSProvider || copyType == BulkCopyType.MultipleRows; } // RowByRow right now uses DataConnection.Insert which doesn't support identity insert if ((copyType == BulkCopyType.RowByRow || context == ProviderName.Access || context == ProviderName.AccessOdbc || notSupported || (context.StartsWith(ProviderName.SapHana) && (copyType == BulkCopyType.MultipleRows || copyType == BulkCopyType.Default)) || (context == ProviderName.SapHanaOdbc && copyType == BulkCopyType.ProviderSpecific)) && keepIdentity == true) { var ex = Assert.CatchAsync(async() => await perform()) !; Assert.IsInstanceOf <LinqToDBException>(ex); Assert.AreEqual("BulkCopyOptions.KeepIdentity = true is not supported by BulkCopyType.RowByRow mode", ex.Message); return(false); } await perform(); return(true); }
void BulkCopyTest(string context, BulkCopyType bulkCopyType) { using (var conn = new DataConnection(context)) { conn.BeginTransaction(); conn.BulkCopy(new BulkCopyOptions { MaxBatchSize = 50, BulkCopyType = bulkCopyType }, Enumerable.Range(0, 100).Select(n => new AllType { ID = 2000 + n, bigintDataType = 3000 + n, smallintDataType = (short)(4000 + n), decimalDataType = 900000 + n, smalldecimalDataType = 90000 + n, intDataType = 7000 + n, tinyintDataType = (byte)(5000 + n), floatDataType = 7700 + n, realDataType = 7600 + n, dateDataType = DateTime.Now, timeDataType = DateTime.Now - DateTime.Today, seconddateDataType = DateTime.Now, timestampDataType = DateTime.Now, charDataType = 'A', varcharDataType = "AA", textDataType = "text", shorttextDataType = "shorttext", ncharDataType = '\u00fc', nvarcharDataType = "A\u00fcfsdf\u00fc", alphanumDataType = "abcQWE654", binaryDataType = new byte[] { 1 }, varbinaryDataType = new byte[] { 1, 2, 3 }, blobDataType = new byte[] { 1, 2, 3, 4, 5, 6 }, clobDataType = "clobclobclob", nclobDataType = "nclob\u00fcnclob\u00fcnclob\u00fc" })); conn.GetTable<AllType>().Delete(p => p.ID >= 2000); } }
private static void TestBulkCopy <TTable, TType>(DataConnection db, TTable[] data, TempTable <TTable> table, BulkCopyType bulkCopyType) where TTable : TypeTable <TType> where TType : struct { table.Delete(); db.BulkCopy(new BulkCopyOptions() { BulkCopyType = bulkCopyType }, data); var records = table.OrderBy(r => r.Id).ToArray(); Assert.AreEqual(2, records.Length); Assert.AreEqual(data[0].Id, records[0].Id); Assert.AreEqual(data[0].Column, records[0].Column); Assert.AreEqual(data[0].ColumnNullable, records[0].ColumnNullable); Assert.AreEqual(data[1].Id, records[1].Id); Assert.AreEqual(data[1].Column, records[1].Column); Assert.AreEqual(data[1].ColumnNullable, records[1].ColumnNullable); }
public async Task KeepIdentity_SkipOnInsertTrue( [DataSources(false)] string context, [Values(null, true, false)] bool?keepIdentity, [Values] BulkCopyType copyType, [Values(0, 1, 2)] int asyncMode) // 0 == sync, 1 == async, 2 == async with IAsyncEnumerable { if ((context == ProviderName.Sybase) && copyType == BulkCopyType.ProviderSpecific && keepIdentity != true) { Assert.Inconclusive("Sybase native bulk copy doesn't support identity insert (despite documentation)"); } ResetAllTypesIdentity(context); if ((context == ProviderName.OracleNative || context == TestProvName.Oracle11Native) && copyType == BulkCopyType.ProviderSpecific) { Assert.Inconclusive("Oracle BulkCopy doesn't support identity triggers"); } // don't use transactions as some providers will fallback to non-provider-specific implementation then using (var db = new TestDataConnection(context)) { var lastId = db.InsertWithInt32Identity(new TestTable2()); try { var options = new BulkCopyOptions() { KeepIdentity = keepIdentity, BulkCopyType = copyType }; if (!await ExecuteAsync(db, context, perform, keepIdentity, copyType)) { return; } var data = db.GetTable <TestTable2>().Where(_ => _.ID > lastId).OrderBy(_ => _.ID).ToArray(); Assert.AreEqual(2, data.Length); // oracle supports identity insert only starting from version 12c, which is not used yet for tests var useGenerated = keepIdentity != true || context.Contains("Oracle"); Assert.AreEqual(lastId + (!useGenerated ? 10 : 1), data[0].ID); Assert.AreEqual(200, data[0].Value); Assert.AreEqual(lastId + (!useGenerated ? 20 : 2), data[1].ID); Assert.AreEqual(300, data[1].Value); async Task perform() { var values = new[] { new TestTable2() { ID = lastId + 10, Value = 200 }, new TestTable2() { ID = lastId + 20, Value = 300 } }; if (asyncMode == 0) // synchronous { db.BulkCopy( options, values); } else if (asyncMode == 1) // asynchronous { await db.BulkCopyAsync( options, values); } else // asynchronous with IAsyncEnumerable { await db.BulkCopyAsync( options, AsAsyncEnumerable(values)); } } } finally { // cleanup db.GetTable <TestTable2>().Delete(_ => _.ID >= lastId); } } }