Esempio n. 1
0
        public async Task SqlBulkTools_BulkUpdateAsyncWithSelectedColumns_TestIdentityOutput()
        {
            _db.Books.RemoveRange(_db.Books.ToList());
            _db.SaveChanges();
            BulkOperations bulk = new BulkOperations();

            List <Book> books = _randomizer.GetRandomCollection(30);

            await BulkInsertAsync(books);

            bulk.Setup <Book>()
            .ForCollection(books)
            .WithTable("Books")
            .AddColumn(x => x.ISBN)
            .AddColumn(x => x.Description)
            .AddColumn(x => x.Title)
            .AddColumn(x => x.Price)
            .BulkUpdate()
            .MatchTargetOn(x => x.ISBN)
            .SetIdentityColumn(x => x.Id, ColumnDirection.InputOutput);

            await bulk.CommitTransactionAsync("SqlBulkToolsTest");

            var test     = _db.Books.ToList().ElementAt(10); // Random book within the 30 elements
            var expected = books.Single(x => x.ISBN == test.ISBN);

            Assert.AreEqual(expected.Id, test.Id);
        }
Esempio n. 2
0
        public async Task SqlBulkTools_BulkUpdateAsyncWithSelectedColumns_TestIdentityOutput()
        {
            _db.Books.RemoveRange(_db.Books.ToList());
            _db.SaveChanges();
            BulkOperations bulk = new BulkOperations();

            List <Book> books = _randomizer.GetRandomCollection(30);

            await BulkInsertAsync(books);

            using (TransactionScope trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager
                                                              .ConnectionStrings["SqlBulkToolsTest"].ConnectionString))
                {
                    await bulk.Setup <Book>()
                    .ForCollection(books)
                    .WithTable("Books")
                    .AddColumn(x => x.ISBN)
                    .AddColumn(x => x.Description)
                    .AddColumn(x => x.Title)
                    .AddColumn(x => x.Price)
                    .BulkUpdate()
                    .MatchTargetOn(x => x.ISBN)
                    .SetIdentityColumn(x => x.Id, ColumnDirectionType.InputOutput)
                    .CommitAsync(conn);
                }

                trans.Complete();
            }

            var test     = _db.Books.ToList().ElementAt(10); // Random book within the 30 elements
            var expected = books.Single(x => x.ISBN == test.ISBN);

            Assert.AreEqual(expected.Id, test.Id);
        }