天天看點

業務邏輯層實作事務處理

業務邏輯層實作事務處理
業務邏輯層實作事務處理

Code

private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e)

{

    UpdateData();

}

private void UpdateData()

    this.Validate();

    this.customersBindingSource.EndEdit();

    this.ordersBindingSource.EndEdit();

    using (System.Transactions.TransactionScope updateTransaction = 

        new System.Transactions.TransactionScope())

    {

        DeleteOrders();

        DeleteCustomers();

        AddNewCustomers();

        AddNewOrders();

        updateTransaction.Complete();

        northwindDataSet.AcceptChanges();

    }

The order for reconciling changes to related data is as follows:

Delete child records (in this case, delete records from the <code>Orders</code> table)

Delete parent records (in this case, delete records from the <code>Customers</code> table)

Insert parent records (in this case, insert records in the <code>Customers</code> table)

Insert child records (in this case, insert records in the <code>Orders</code> table)

版權

作者:靈動生活 郝憲玮

如果你認為此文章有用,請點選底端的【推薦】讓其他人也了解此文章,

業務邏輯層實作事務處理

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利。

繼續閱讀