Пример #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();
        }
Пример #2
0
        public static void DoWithTransaction()
        {
            using (ITransientTransaction tran = context.BeginTransaction())
            {
                /* do some things here */
                context.Update <User>(a => a.Id == 1, a => new User()
                {
                    Name = a.Name, Age = a.Age + 1, Gender = Gender.Man, OpTime = DateTime.Now
                });
                context.Delete <User>(a => a.Id == 1024);

                tran.Commit();
            }

            ConsoleHelper.WriteLineAndReadKey();
        }