日期:2014-05-20 浏览次数:21194 次
var confirmReject = MessageBox.Show("放弃所有修改?", "Confirm", MessageBoxButtons.OKCancel);  
if (confirmReject == System.Windows.Forms.DialogResult.OK)  
{  
    northwind.Refresh(RefreshMode.StoreWins, northwind.Customers);  
    northwind.AcceptAllChanges();  
}
------解决方案--------------------
 System.Data.Common.DbTransaction tran = null;
try
{
  DBContext.Connection.Open();
  tran = DBContext.Connection.BeginTransaction();
.....
 DBContext.SaveChanges();
 tran.Commit();
}
           catch (Exception ex)
           {
               if (tran != null)
                   tran.Rollback();
               throw ex;
           }
------解决方案--------------------
 db.Product.Attach(item);
                db.ObjectStateManager.ChangeObjectState(item, EntityState.Added);