Пример #1
0
        private static void Search()
        {
            var dbContext = NPocoHelper.GetNewInstance(_connStr);
            var result    = dbContext.FirstOrDefault <User1>("select * from User1 where LoginCode='test01'");

            Console.WriteLine("Name:" + result.Name);
        }
Пример #2
0
        private static void Delete()
        {
            var dbContext = NPocoHelper.GetNewInstance(_connStr);
            var result    = dbContext.FirstOrDefault <User1>("select * from User1 where LoginCode='test01'");
            var count     = dbContext.Delete(result);

            Console.WriteLine("Count:" + count);
        }
Пример #3
0
        private static void Update()
        {
            var dbContext = NPocoHelper.GetNewInstance(_connStr);
            var result    = dbContext.First <User1>("where LoginCode='test01'");

            result.Password = "******";
            dbContext.Update <User1>(result, (a) => a.Password);
            result = dbContext.First <User1>("where LoginCode='test01'");
            Console.WriteLine("password:" + result.Password);
        }
Пример #4
0
        private static void Add()
        {
            var dbContext = NPocoHelper.GetNewInstance(_connStr);
            var result    = dbContext.Insert <User1>(new User1()
            {
                LoginCode = "test01", Name = "test01", Password = "******"
            });

            Console.WriteLine("add result:" + result);
        }
Пример #5
0
        private static void ExecTran(bool isSuccess)
        {
            var dbContext = NPocoHelper.GetNewInstance(_connStr);
            var newUser   = new User1()
            {
                LoginCode = "test02", Name = "test02", Password = "******"
            };

            //var tran=dbContext.GetTransaction();
            dbContext.BeginTransaction();


            var result = dbContext.Insert <User1>(newUser);

            newUser.LoginCode = "test0201";
            result            = dbContext.Insert <User1>(newUser);

            if (isSuccess)
            {
                dbContext.CompleteTransaction();
            }
            else
            {
                dbContext.AbortTransaction();
            }


            var user = dbContext.FirstOrDefault <User1>("select * from User1 where LoginCode=@LoginCode", newUser);

            if (user == null)
            {
                Console.WriteLine("User 未添加成功");
            }
            else
            {
                Console.WriteLine("User 添加成功");
                //清理数据
                dbContext.Delete(user);
                dbContext.Delete <User1>("where LoginCode='test02'");
            }
        }