public void TestNestClass()
        {
            var connectString = TestUtils.GetLocalDBConnectionString();
            Database.SetInitializer(new DropCreateDatabaseAlways<NestContext>());
            var context = new NestContext(connectString);
            context.NestInits.Add(new NestInit());
            context.SaveChanges();

            var a1 = new ABulk {};
            var a2 = new ABulk {B = new B { } };
            var a3 = new ABulk {B = new B { Value2 = "a" } };
            var a4 = new ABulk {Value1 = "a", B = new B { Value2 = "a" } };
            
            using (var connection = new SqlConnection(connectString))
            {
                connection.Open();
                var aTypeAccessor = TypeAccessorManager<ABulk>.GetAccessorForTable(new TargetTable("NestClassTest", connectString, "dbo.AEFs"));
                var aReader = new BulkDataReader<ABulk>(aTypeAccessor, new[] { a1, a2, a3, a4 });
                using (var aCopy = new SqlBulkCopy(connection))
                {
                    foreach (var map in aReader.ColumnMappings)
                    {
                        aCopy.ColumnMappings.Add(map);
                    }
                    aCopy.DestinationTableName = "dbo.AEFs";
                    aCopy.WriteToServer(aReader);
                }
            }

            Assert.AreEqual(1, context.AAs.FirstOrDefault().Id);
            Assert.AreEqual(1, context.AAs.Count(a => a.Value1 == "a"));
            Assert.AreEqual(3, context.AAs.Count(a => a.Value1 == "-"));
            Assert.AreEqual(2, context.AAs.Count(a => a.Value2 == "a"));
            Assert.AreEqual(2, context.AAs.Count(a => a.Value2 == "--"));
        }
Exemple #2
0
        public void TestNestClass()
        {
            var connectString = TestUtils.GetLocalDBConnectionString();

            Database.SetInitializer(new DropCreateDatabaseAlways <NestContext>());
            var context = new NestContext(connectString);

            context.NestInits.Add(new NestInit());
            context.SaveChanges();

            var a1 = new ABulk {
            };
            var a2 = new ABulk {
                B = new B {
                }
            };
            var a3 = new ABulk {
                B = new B {
                    Value2 = "a"
                }
            };
            var a4 = new ABulk {
                Value1 = "a", B = new B {
                    Value2 = "a"
                }
            };

            using (var connection = new SqlConnection(connectString))
            {
                connection.Open();
                var aTypeAccessor = TypeAccessorManager <ABulk> .GetAccessorForTable(new TargetTable("NestClassTest", connectString, "dbo.AEFs"));

                var aReader = new BulkDataReader <ABulk>(aTypeAccessor, new[] { a1, a2, a3, a4 });
                using (var aCopy = new SqlBulkCopy(connection))
                {
                    foreach (var map in aReader.ColumnMappings)
                    {
                        aCopy.ColumnMappings.Add(map);
                    }
                    aCopy.DestinationTableName = "dbo.AEFs";
                    aCopy.WriteToServer(aReader);
                }
            }

            Assert.AreEqual(1, context.AAs.FirstOrDefault().Id);
            Assert.AreEqual(1, context.AAs.Count(a => a.Value1 == "a"));
            Assert.AreEqual(3, context.AAs.Count(a => a.Value1 == "-"));
            Assert.AreEqual(2, context.AAs.Count(a => a.Value2 == "a"));
            Assert.AreEqual(2, context.AAs.Count(a => a.Value2 == "--"));
        }