日期:2014-05-20  浏览次数:20888 次

linq 修改提交给事物拦截后再次提交不更新数据库

 bool bo = false;
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
            {
                try
                {
                    CoreProject.Service.EmployeeService.GetSObj.aa(userState.Employee, bo);
                    
                   
                    scope.Complete();//提交事务                  
                }
                catch (Exception ee)
                {
                    bo = true;                  
                    this.ShowMessageBox(ee.Message);
                }
                finally
                {
                    scope.Dispose();//回滚事务
                }
            }
        }

//-----------在EmployeeService类中的方法

public void UpdateName(Employee employee, bool bo)
        {
            var obj = (from d in db.DEF_Employee where d.Id == employee.Id select d).SingleOrDefault();
            if (obj == null)
                return;

            obj.Name = "aaaa";
            db.SubmitChanges()
            if (!bo)
            {
                //db = new DataDBDDataContext(ConStr);