के साथ ट्रांज़ेक्शनस्कोप का उपयोग करना मैं समझ नहीं पा रहा हूं कि संदर्भ में परिवर्तन करना संभव है और इसके पहले ही लेनदेन में परिवर्तन करने से पहले यह संभव है।एंटीटी फ्रेमवर्क 6
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
using (var context = new DbContext())
{
//first I want to update an item in the context, not to the db
Item thisItem = context.Items.First();
thisItem.Name = "Update name";
context.SaveChanges(); //Save change to this context
//then I want to do a query on the updated item on the current context, not against the db
Item thisUpdatedItem = context.Items.Where(a=>a.Name == "Update name").First();
//do some more query
}
//First here I want it to commit all the changes in the current context to the db
scope.Complete();
}
किसी की मदद कर सकते हैं मुझे समझने और मुझे एक काम पैटर्न दिखाने:
यह मैं के लिए क्या देख रहा है?
क्या यह डीबी में पंक्ति डालेगा और फिर यदि लेनदेन रोलबैक किया गया है तो क्या यह पंक्ति को हटा देगा? या आप पंक्ति की आईडी कैसे प्राप्त करते हैं? @ kienct89 –
जब तक आप लेनदेन को कॉल नहीं करते हैं तब तक यह डीबी में पंक्ति नहीं डालेगा। कॉमिट(), आईडी अस्थायी रूप से स्मृति –
मेमोरी में असाइन की जाएगी, उदाहरण और विवरण के लिए धन्यवाद। मैं इसका परीक्षण करूंगा और आपको वापस ले जाऊंगा –