public async Task ConcurrencyException()
        {
            var db = new EasyDb();

            db.SetConnectionStringSettings(@"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=MyDb;Integrated Security=True", DbConstants.SqlProviderName);

            db.AddInterceptor(new ConcurrencyInterceptor());

            db.SetTable <UserWithRowVersion>("User")
            .SetPrimaryKeyColumn("Id", p => p.Id)
            .SetColumn("Version", p => p.Version, true);

            var model = await db.SelectOneAsync <UserWithRowVersion>(Check.Op("Id", 2));

            model.UserName  += " updated";
            model.Version[4] = 2;

            bool failed = false;

            try
            {
                int result = await db.UpdateAsync <UserWithRowVersion>(model, Check.Op("Id", model.Id).And(Check.Op("Version", model.Version)));
            }
            catch (OptimisticConcurrencyException ex)
            {
                failed = true;
            }

            Assert.IsTrue(failed);
        }
示例#2
0
        public async Task Update_WithFactory()
        {
            var db = new EasyDb();

            db.SetConnectionStringSettings(DbConstants.SqlDb1, DbConstants.SqlProviderName);

            db.DefaultMappingBehavior = DefaultMappingBehavior.CreateEmptyTable;

            var model = await db.SelectOneAsync <User>(Check.Op("Id", 4));

            model.UserName += " updated";
            int result = await db.UpdateAsync <User>(new UserUdpateFactory(), model);

            Assert.AreEqual(1, result);
        }
示例#3
0
        public async Task Update()
        {
            var db = new EasyDb();

            db.DefaultMappingBehavior = DefaultMappingBehavior.CreateEmptyTable;

            db.SetTable <User>("User")
            .SetPrimaryKeyColumn("Id", p => p.Id);

            db.SetConnectionStringSettings(DbConstants.SqlDb1, DbConstants.SqlProviderName);

            var model = await db.SelectOneAsync <User>(Check.Op("Id", 2));

            model.UserName += " updated";
            var result = await db.UpdateAsync <User>(model, Check.Op("Id", model.Id));

            Assert.AreEqual(1, result);
        }