Exemplo n.º 1
0
        public static void BulkCopyTest()
        {
            List <TestEntity> models = new List <TestEntity>();

            models.Add(new TestEntity()
            {
                Id         = 14,
                F_Byte     = 1,
                F_Int16    = 1,
                F_Int32    = 1,
                F_Int64    = 1,
                F_Double   = 1,
                F_Float    = 1,
                F_Decimal  = 1,
                F_Bool     = true,
                F_DateTime = DateTime.Now,
                F_String   = "lu"
            });
            models.Add(new TestEntity()
            {
                Id         = 15,
                F_Byte     = 1,
                F_Int16    = 1,
                F_Int32    = 1,
                F_Int64    = 1,
                F_Double   = 1,
                F_Float    = 1,
                F_Decimal  = 1,
                F_Bool     = true,
                F_DateTime = DateTime.Now,
                F_Guid     = Guid.NewGuid(),
                F_String   = "so"
            });

            object result = null;

            //SqlConnection conn = new SqlConnection(DbHelper.ConnectionString);
            //conn.BulkCopy1<TestEntity>(models, int.MaxValue, null, null, null);

            context.BeginTransaction();
            result = context.Query <User>().Select(a => new UserLite()
            {
                Id = a.Id, Name = a.Name
            }).ToList();

            context.BulkInsert(models, null, null, false);

            result = context.Query <User>().Select(a => new UserLite()
            {
                Id = a.Id, Name = a.Name
            }).ToList();

            context.CommitTransaction();

            Console.WriteLine(1);
            Console.ReadKey();
        }