public void InsertBatchInvoiceWithInvoiceForEachExistingJournal() { using (var db = new InvoiceContext()) { for (int i = 0; i < 10; i++) { db.Journals.Add(new Journal() { Id = Guid.NewGuid() }); } db.SaveChanges(); var batchInvoice = new BatchInvoice { Id = Guid.NewGuid() }; foreach (var journal in db.Journals.ToList()) { var invoice = new Invoice() { Id = Guid.NewGuid() }; invoice.Journals.Add(new InvoiceItem() { JournalId = journal.Id }); batchInvoice.Invoices.Add(new BatchInvoiceItem() { Id = Guid.NewGuid(), Invoice = invoice }); } var req = new BulkInsertRequest <BatchInvoice> { Entities = new[] { batchInvoice }.ToList(), AllowNotNullSelfReferences = AllowNotNullSelfReferences.No, SortUsingClusteredIndex = true, EnableRecursiveInsert = EnableRecursiveInsert.Yes }; var response = db.BulkInsertAll(req); Assert.AreEqual(1, db.BatchInvoices.ToArray().Count()); Assert.AreEqual(10, db.BatchInvoiceItems.ToArray().Count()); Assert.AreEqual(10, db.Invoices.ToArray().Count()); Assert.AreEqual(10, db.InvoiceItems.ToArray().Count()); } }
public void InsertEntityWithComputedColumnInTableWithUserGeneratedPrimaryKeyShouldWork() { using (var db = new UnitTestContext()) { for (int i = 0; i < 10; i++) { db.Journals.Add(new Journal() { Id = Guid.NewGuid() }); } db.SaveChanges(); var batchInvoice = new BatchInvoice { Id = Guid.NewGuid() }; foreach (var journal in db.Journals.ToList()) { var invoice = new Invoice() { Id = Guid.NewGuid(), Gross = 10, Net = 3 }; invoice.Journals.Add(new InvoiceItem() { JournalId = journal.Id }); batchInvoice.Invoices.Add(new BatchInvoiceItem() { Id = Guid.NewGuid(), Invoice = invoice }); } var req = new BulkInsertRequest <BatchInvoice> { Entities = new[] { batchInvoice }.ToList(), AllowNotNullSelfReferences = AllowNotNullSelfReferences.No, SortUsingClusteredIndex = true, EnableRecursiveInsert = EnableRecursiveInsert.Yes }; var response = db.BulkInsertAll(req); Assert.AreEqual(1, db.BatchInvoices.ToArray().Count()); Assert.AreEqual(10, db.BatchInvoiceItems.ToArray().Count()); Assert.AreEqual(10, db.Invoices.ToArray().Count()); Assert.AreEqual(10, db.InvoiceItems.ToArray().Count()); } }