簡體   English   中英

跨多種方法的TransactionScope不是ACID?

[英]TransactionScope across Multiple Methods is not ACID?

我有這樣的代碼:

using (TransactionScope transactionScope = new TransactionScope())
        {
            SetDefaults(products);

            // Map the SizeCollectionIds of the products
            _dataAccess.MapProductSizes(products);

            // Mass update and insert missing parent records to the database
            _dataAccess.UpdateParents(products);

            // Get ids of parent products that were newly inserted
            _dataAccess.PopulateParentProductByParentSku(products);

            // Insert children into database
            _dataAccess.InsertProducts(products);

            // Insert the UPCs into the database
            _dataAccess.InsertUPCs(products);

            // Get Product Ids of newly inserted records
            _dataAccess.PopulateProductIds(products);

            // Get just the parent products to insert the brands
            List<ParentProduct> parents = (from prod in products
                                           select prod.ParentProduct).Distinct().ToList();

            // Insert ParentProductBrand record
            _dataAccess.InsertParentProductBrands(parents);

            // Insert the custom attribute records
            _dataAccess.InsertProductCustomAttributes(products);

            transactionScope.Complete();
        }

我想要的是,如果在事務范圍內調用的方法中的任何地方發生錯誤,那么事務就會被回滾,但是經過一些測試后,似乎情況並非如此,我的數據最終會被燒掉一半。 有什么我想念的嗎? 我是否必須在自己的TransactionScopes中將方法本身中的數據訪問調用包裝起來才能使其工作?

在您的DataAccess層中看起來像是創建了幾個數據庫連接實例。 嘗試在DataAccess類構造函數中實例化數據庫連接,並在DataAccess方法中使用它。 您可能想閱讀此博文

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM