[{"data":1,"prerenderedAt":2973},["ShallowReactive",2],{"blog:2025:mongodb-explicit-transactions":3,"blogMore-Development":2959,"comments-mongodb-explicit-transactions":2972},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"category":14,"excerpt":15,"body":30,"_type":2950,"_id":2951,"_source":2952,"_file":2953,"_stem":2954,"_extension":2955,"url":2956,"wordCount":2957,"minutes":721,"commentCount":2958},"/blog/2025/mongodb-explicit-transactions","2025",false,"en","Transactions in the MongoDB EF Core Provider","Database transactions ensure that multi-record (or in our case multi-document) operations either all succeed or all fail together.","2025-10-25",[12,13],"Entity Framework","MongoDB","Development",{"type":16,"children":17},"root",[18,25],{"type":19,"tag":20,"props":21,"children":22},"element","p",{},[23],{"type":24,"value":9},"text",{"type":19,"tag":20,"props":26,"children":27},{},[28],{"type":24,"value":29},"This is absolutely critical for data consistency in your applications. EF Core has support for three different types of transactions: implicit, explicit, and ambient.",{"type":16,"children":31,"toc":2932},[32,36,40,45,50,57,68,73,80,85,145,150,156,172,208,221,354,360,365,379,385,390,396,425,430,928,940,1201,1206,1212,1217,1249,1254,2008,2026,2032,2046,2059,2065,2071,2076,2207,2243,2249,2254,2691,2711,2731,2737,2742,2802,2815,2820,2833,2839,2844,2849,2902,2916,2921,2926],{"type":19,"tag":20,"props":33,"children":34},{},[35],{"type":24,"value":9},{"type":19,"tag":20,"props":37,"children":38},{},[39],{"type":24,"value":29},{"type":19,"tag":20,"props":41,"children":42},{},[43],{"type":24,"value":44},"Our upcoming 9.0.3 release adds explicit transaction support, joining the implicit transaction support we added in August 2024.",{"type":19,"tag":20,"props":46,"children":47},{},[48],{"type":24,"value":49},"Let's cover how the different types of transactions behave and can be used.",{"type":19,"tag":51,"props":52,"children":54},"h2",{"id":53},"setup-mongodb-for-transactions",[55],{"type":24,"value":56},"Setup MongoDB for transactions",{"type":19,"tag":20,"props":58,"children":59},{},[60,62],{"type":24,"value":61},"We need MongoDB running in a transaction-capable mode such as replica set or sharded cluster configuration. ",{"type":19,"tag":63,"props":64,"children":65},"strong",{},[66],{"type":24,"value":67},"Note: The default standalone mode does not support transactions.",{"type":19,"tag":20,"props":69,"children":70},{},[71],{"type":24,"value":72},"The good news is that it's easy to run MongoDB in replica set mode, and you have several options:",{"type":19,"tag":74,"props":75,"children":77},"h3",{"id":76},"docker",[78],{"type":24,"value":79},"Docker",{"type":19,"tag":20,"props":81,"children":82},{},[83],{"type":24,"value":84},"Docker is an easy way to get started. The mongodb-atlas-local image provides replica set transaction support by default, plus vector and text search capabilities.",{"type":19,"tag":86,"props":87,"children":92},"pre",{"className":88,"code":89,"language":90,"meta":91,"style":91},"language-bash shiki shiki-themes everforest-light dracula","docker run --name mongodb-atlas-local -p 27017:27017 -d mongodb/mongodb-atlas-local\n","bash","",[93],{"type":19,"tag":94,"props":95,"children":96},"code",{"__ignoreMap":91},[97],{"type":19,"tag":98,"props":99,"children":102},"span",{"class":100,"line":101},"line",1,[103,108,114,120,125,130,135,140],{"type":19,"tag":98,"props":104,"children":106},{"style":105},"--shiki-default:#8DA101;--shiki-dark:#50FA7B",[107],{"type":24,"value":76},{"type":19,"tag":98,"props":109,"children":111},{"style":110},"--shiki-default:#DFA000;--shiki-dark:#F1FA8C",[112],{"type":24,"value":113}," run",{"type":19,"tag":98,"props":115,"children":117},{"style":116},"--shiki-default:#DFA000;--shiki-dark:#BD93F9",[118],{"type":24,"value":119}," --name",{"type":19,"tag":98,"props":121,"children":122},{"style":110},[123],{"type":24,"value":124}," mongodb-atlas-local",{"type":19,"tag":98,"props":126,"children":127},{"style":116},[128],{"type":24,"value":129}," -p",{"type":19,"tag":98,"props":131,"children":132},{"style":110},[133],{"type":24,"value":134}," 27017:27017",{"type":19,"tag":98,"props":136,"children":137},{"style":116},[138],{"type":24,"value":139}," -d",{"type":19,"tag":98,"props":141,"children":142},{"style":110},[143],{"type":24,"value":144}," mongodb/mongodb-atlas-local\n",{"type":19,"tag":20,"props":146,"children":147},{},[148],{"type":24,"value":149},"This fetches the latest Atlas-capable MongoDB image for Docker and runs it locally, binding it to port 27017 (MongoDB's default port).",{"type":19,"tag":74,"props":151,"children":153},{"id":152},"manual-setup",[154],{"type":24,"value":155},"Manual setup",{"type":19,"tag":20,"props":157,"children":158},{},[159,161,170],{"type":24,"value":160},"If you prefer to run MongoDB directly, ",{"type":19,"tag":162,"props":163,"children":167},"a",{"href":164,"rel":165},"https://www.mongodb.com/try/download/community/",[166],"nofollow",[168],{"type":24,"value":169},"download MongoDB Community Server",{"type":24,"value":171}," and start it with the replica set option:",{"type":19,"tag":86,"props":173,"children":175},{"className":88,"code":174,"language":90,"meta":91,"style":91},"mongod --replSet rs0 --port 27017\n",[176],{"type":19,"tag":94,"props":177,"children":178},{"__ignoreMap":91},[179],{"type":19,"tag":98,"props":180,"children":181},{"class":100,"line":101},[182,187,192,197,202],{"type":19,"tag":98,"props":183,"children":184},{"style":105},[185],{"type":24,"value":186},"mongod",{"type":19,"tag":98,"props":188,"children":189},{"style":116},[190],{"type":24,"value":191}," --replSet",{"type":19,"tag":98,"props":193,"children":194},{"style":110},[195],{"type":24,"value":196}," rs0",{"type":19,"tag":98,"props":198,"children":199},{"style":116},[200],{"type":24,"value":201}," --port",{"type":19,"tag":98,"props":203,"children":205},{"style":204},"--shiki-default:#DF69BA;--shiki-dark:#BD93F9",[206],{"type":24,"value":207}," 27017\n",{"type":19,"tag":20,"props":209,"children":210},{},[211,213,219],{"type":24,"value":212},"Then connect with ",{"type":19,"tag":94,"props":214,"children":216},{"className":215},[],[217],{"type":24,"value":218},"mongosh",{"type":24,"value":220}," and initialize the replica set:",{"type":19,"tag":86,"props":222,"children":226},{"className":223,"code":224,"language":225,"meta":91,"style":91},"language-javascript shiki shiki-themes everforest-light dracula","rs.initiate({\n  _id: \"rs0\",\n  members: [{ _id: 0, host: \"localhost:27017\" }],\n})\n","javascript",[227],{"type":19,"tag":94,"props":228,"children":229},{"__ignoreMap":91},[230,255,291,345],{"type":19,"tag":98,"props":231,"children":232},{"class":100,"line":101},[233,239,245,250],{"type":19,"tag":98,"props":234,"children":236},{"style":235},"--shiki-default:#5C6A72;--shiki-dark:#F8F8F2",[237],{"type":24,"value":238},"rs",{"type":19,"tag":98,"props":240,"children":242},{"style":241},"--shiki-default:#939F91;--shiki-dark:#F8F8F2",[243],{"type":24,"value":244},".",{"type":19,"tag":98,"props":246,"children":247},{"style":105},[248],{"type":24,"value":249},"initiate",{"type":19,"tag":98,"props":251,"children":252},{"style":235},[253],{"type":24,"value":254},"({\n",{"type":19,"tag":98,"props":256,"children":258},{"class":100,"line":257},2,[259,264,270,276,281,286],{"type":19,"tag":98,"props":260,"children":261},{"style":235},[262],{"type":24,"value":263},"  _id",{"type":19,"tag":98,"props":265,"children":267},{"style":266},"--shiki-default:#939F91;--shiki-dark:#FF79C6",[268],{"type":24,"value":269},":",{"type":19,"tag":98,"props":271,"children":273},{"style":272},"--shiki-default:#DFA000;--shiki-dark:#E9F284",[274],{"type":24,"value":275}," \"",{"type":19,"tag":98,"props":277,"children":278},{"style":110},[279],{"type":24,"value":280},"rs0",{"type":19,"tag":98,"props":282,"children":283},{"style":272},[284],{"type":24,"value":285},"\"",{"type":19,"tag":98,"props":287,"children":288},{"style":235},[289],{"type":24,"value":290},",\n",{"type":19,"tag":98,"props":292,"children":294},{"class":100,"line":293},3,[295,300,304,309,313,318,323,327,331,336,340],{"type":19,"tag":98,"props":296,"children":297},{"style":235},[298],{"type":24,"value":299},"  members",{"type":19,"tag":98,"props":301,"children":302},{"style":266},[303],{"type":24,"value":269},{"type":19,"tag":98,"props":305,"children":306},{"style":235},[307],{"type":24,"value":308}," [{ _id",{"type":19,"tag":98,"props":310,"children":311},{"style":266},[312],{"type":24,"value":269},{"type":19,"tag":98,"props":314,"children":315},{"style":204},[316],{"type":24,"value":317}," 0",{"type":19,"tag":98,"props":319,"children":320},{"style":235},[321],{"type":24,"value":322},", host",{"type":19,"tag":98,"props":324,"children":325},{"style":266},[326],{"type":24,"value":269},{"type":19,"tag":98,"props":328,"children":329},{"style":272},[330],{"type":24,"value":275},{"type":19,"tag":98,"props":332,"children":333},{"style":110},[334],{"type":24,"value":335},"localhost:27017",{"type":19,"tag":98,"props":337,"children":338},{"style":272},[339],{"type":24,"value":285},{"type":19,"tag":98,"props":341,"children":342},{"style":235},[343],{"type":24,"value":344}," }],\n",{"type":19,"tag":98,"props":346,"children":348},{"class":100,"line":347},4,[349],{"type":19,"tag":98,"props":350,"children":351},{"style":235},[352],{"type":24,"value":353},"})\n",{"type":19,"tag":74,"props":355,"children":357},{"id":356},"atlas-cloud",[358],{"type":24,"value":359},"Atlas Cloud",{"type":19,"tag":20,"props":361,"children":362},{},[363],{"type":24,"value":364},"MongoDB Atlas Cloud provides replica sets by default, so if you're already using it, you're all set.",{"type":19,"tag":20,"props":366,"children":367},{},[368,370,377],{"type":24,"value":369},"Alternatively, you can install the ",{"type":19,"tag":162,"props":371,"children":374},{"href":372,"rel":373},"https://www.mongodb.com/docs/atlas/cli/current/",[166],[375],{"type":24,"value":376},"MongoDB Atlas CLI",{"type":24,"value":378},", which will guide you through setting up an Atlas account and creating your cluster.",{"type":19,"tag":51,"props":380,"children":382},{"id":381},"understanding-transaction-types",[383],{"type":24,"value":384},"Understanding transaction types",{"type":19,"tag":20,"props":386,"children":387},{},[388],{"type":24,"value":389},"The MongoDB EF Core Provider provides support for both implicit and explicit transactions. Implicit is simple and automatic while explicit gives you more control for performing multi-step operations.",{"type":19,"tag":74,"props":391,"children":393},{"id":392},"implicit-transactions",[394],{"type":24,"value":395},"Implicit transactions",{"type":19,"tag":20,"props":397,"children":398},{},[399,401,407,409,415,417,423],{"type":24,"value":400},"Implicit transactions are automatically created when ",{"type":19,"tag":94,"props":402,"children":404},{"className":403},[],[405],{"type":24,"value":406},"SaveChanges",{"type":24,"value":408}," (or ",{"type":19,"tag":94,"props":410,"children":412},{"className":411},[],[413],{"type":24,"value":414},"SaveChangesAsync",{"type":24,"value":416},") detects multiple documents being modified, inserted, or deleted. Note: You can disable this behavior through the ",{"type":19,"tag":94,"props":418,"children":420},{"className":419},[],[421],{"type":24,"value":422},"AutoTransactions",{"type":24,"value":424}," option, though this is not recommended.",{"type":19,"tag":20,"props":426,"children":427},{},[428],{"type":24,"value":429},"Let's look at a simple bank account transfer example. Here's our minimal model and DbContext subclass with setup code:",{"type":19,"tag":86,"props":431,"children":435},{"className":432,"code":433,"language":434,"meta":91,"style":91},"language-csharp shiki shiki-themes everforest-light dracula","public record Account(ObjectId Id, string Number, decimal Balance);\npublic record AuditLog(ObjectId Id, DateTime Timestamp, string Action, string Details);\n\npublic class BankContext(DbContextOptions\u003CBankContext> options) : DbContext(options)\n{\n    public DbSet\u003CAccount> Accounts { get; set; }\n    public DbSet\u003CAuditLog> AuditLogs { get; set; }\n}\n\nvar optionsBuilder = new DbContextOptionsBuilder\u003CBankContext>()\n    .UseMongoDB(\"mongodb://localhost:27017/?directConnect=True\", \"banking\");\n\nusing var db = new BankContext(optionsBuilder.Options);\n","csharp",[436],{"type":19,"tag":94,"props":437,"children":438},{"__ignoreMap":91},[439,511,583,592,662,671,719,761,770,778,820,874,882],{"type":19,"tag":98,"props":440,"children":441},{"class":100,"line":101},[442,448,454,460,465,471,477,482,487,492,496,501,506],{"type":19,"tag":98,"props":443,"children":445},{"style":444},"--shiki-default:#F57D26;--shiki-dark:#FF79C6",[446],{"type":24,"value":447},"public",{"type":19,"tag":98,"props":449,"children":451},{"style":450},"--shiki-default:#3A94C5;--shiki-dark:#FF79C6",[452],{"type":24,"value":453}," record",{"type":19,"tag":98,"props":455,"children":457},{"style":456},"--shiki-default:#3A94C5;--shiki-dark:#8BE9FD",[458],{"type":24,"value":459}," Account",{"type":19,"tag":98,"props":461,"children":462},{"style":235},[463],{"type":24,"value":464},"(",{"type":19,"tag":98,"props":466,"children":468},{"style":467},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[469],{"type":24,"value":470},"ObjectId",{"type":19,"tag":98,"props":472,"children":474},{"style":473},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#FFB86C;--shiki-dark-font-style:italic",[475],{"type":24,"value":476}," Id",{"type":19,"tag":98,"props":478,"children":479},{"style":235},[480],{"type":24,"value":481},", ",{"type":19,"tag":98,"props":483,"children":484},{"style":450},[485],{"type":24,"value":486},"string",{"type":19,"tag":98,"props":488,"children":489},{"style":473},[490],{"type":24,"value":491}," Number",{"type":19,"tag":98,"props":493,"children":494},{"style":235},[495],{"type":24,"value":481},{"type":19,"tag":98,"props":497,"children":498},{"style":450},[499],{"type":24,"value":500},"decimal",{"type":19,"tag":98,"props":502,"children":503},{"style":473},[504],{"type":24,"value":505}," Balance",{"type":19,"tag":98,"props":507,"children":508},{"style":235},[509],{"type":24,"value":510},");\n",{"type":19,"tag":98,"props":512,"children":513},{"class":100,"line":257},[514,518,522,527,531,535,539,543,548,553,557,561,566,570,574,579],{"type":19,"tag":98,"props":515,"children":516},{"style":444},[517],{"type":24,"value":447},{"type":19,"tag":98,"props":519,"children":520},{"style":450},[521],{"type":24,"value":453},{"type":19,"tag":98,"props":523,"children":524},{"style":456},[525],{"type":24,"value":526}," AuditLog",{"type":19,"tag":98,"props":528,"children":529},{"style":235},[530],{"type":24,"value":464},{"type":19,"tag":98,"props":532,"children":533},{"style":467},[534],{"type":24,"value":470},{"type":19,"tag":98,"props":536,"children":537},{"style":473},[538],{"type":24,"value":476},{"type":19,"tag":98,"props":540,"children":541},{"style":235},[542],{"type":24,"value":481},{"type":19,"tag":98,"props":544,"children":545},{"style":467},[546],{"type":24,"value":547},"DateTime",{"type":19,"tag":98,"props":549,"children":550},{"style":473},[551],{"type":24,"value":552}," Timestamp",{"type":19,"tag":98,"props":554,"children":555},{"style":235},[556],{"type":24,"value":481},{"type":19,"tag":98,"props":558,"children":559},{"style":450},[560],{"type":24,"value":486},{"type":19,"tag":98,"props":562,"children":563},{"style":473},[564],{"type":24,"value":565}," Action",{"type":19,"tag":98,"props":567,"children":568},{"style":235},[569],{"type":24,"value":481},{"type":19,"tag":98,"props":571,"children":572},{"style":450},[573],{"type":24,"value":486},{"type":19,"tag":98,"props":575,"children":576},{"style":473},[577],{"type":24,"value":578}," Details",{"type":19,"tag":98,"props":580,"children":581},{"style":235},[582],{"type":24,"value":510},{"type":19,"tag":98,"props":584,"children":585},{"class":100,"line":293},[586],{"type":19,"tag":98,"props":587,"children":589},{"emptyLinePlaceholder":588},true,[590],{"type":24,"value":591},"\n",{"type":19,"tag":98,"props":593,"children":594},{"class":100,"line":347},[595,599,605,610,614,619,624,629,634,639,644,649,653,657],{"type":19,"tag":98,"props":596,"children":597},{"style":444},[598],{"type":24,"value":447},{"type":19,"tag":98,"props":600,"children":602},{"style":601},"--shiki-default:#F85552;--shiki-dark:#FF79C6",[603],{"type":24,"value":604}," class",{"type":19,"tag":98,"props":606,"children":607},{"style":456},[608],{"type":24,"value":609}," BankContext",{"type":19,"tag":98,"props":611,"children":612},{"style":235},[613],{"type":24,"value":464},{"type":19,"tag":98,"props":615,"children":616},{"style":467},[617],{"type":24,"value":618},"DbContextOptions",{"type":19,"tag":98,"props":620,"children":621},{"style":235},[622],{"type":24,"value":623},"\u003C",{"type":19,"tag":98,"props":625,"children":626},{"style":467},[627],{"type":24,"value":628},"BankContext",{"type":19,"tag":98,"props":630,"children":631},{"style":235},[632],{"type":24,"value":633},"> ",{"type":19,"tag":98,"props":635,"children":636},{"style":473},[637],{"type":24,"value":638},"options",{"type":19,"tag":98,"props":640,"children":641},{"style":235},[642],{"type":24,"value":643},") : ",{"type":19,"tag":98,"props":645,"children":646},{"style":467},[647],{"type":24,"value":648},"DbContext",{"type":19,"tag":98,"props":650,"children":651},{"style":235},[652],{"type":24,"value":464},{"type":19,"tag":98,"props":654,"children":655},{"style":467},[656],{"type":24,"value":638},{"type":19,"tag":98,"props":658,"children":659},{"style":235},[660],{"type":24,"value":661},")\n",{"type":19,"tag":98,"props":663,"children":665},{"class":100,"line":664},5,[666],{"type":19,"tag":98,"props":667,"children":668},{"style":235},[669],{"type":24,"value":670},"{\n",{"type":19,"tag":98,"props":672,"children":674},{"class":100,"line":673},6,[675,680,685,689,694,699,704,709,714],{"type":19,"tag":98,"props":676,"children":677},{"style":444},[678],{"type":24,"value":679},"    public",{"type":19,"tag":98,"props":681,"children":682},{"style":467},[683],{"type":24,"value":684}," DbSet",{"type":19,"tag":98,"props":686,"children":687},{"style":235},[688],{"type":24,"value":623},{"type":19,"tag":98,"props":690,"children":691},{"style":467},[692],{"type":24,"value":693},"Account",{"type":19,"tag":98,"props":695,"children":696},{"style":235},[697],{"type":24,"value":698},"> Accounts { ",{"type":19,"tag":98,"props":700,"children":701},{"style":450},[702],{"type":24,"value":703},"get",{"type":19,"tag":98,"props":705,"children":706},{"style":235},[707],{"type":24,"value":708},"; ",{"type":19,"tag":98,"props":710,"children":711},{"style":450},[712],{"type":24,"value":713},"set",{"type":19,"tag":98,"props":715,"children":716},{"style":235},[717],{"type":24,"value":718},"; }\n",{"type":19,"tag":98,"props":720,"children":722},{"class":100,"line":721},7,[723,727,731,735,740,745,749,753,757],{"type":19,"tag":98,"props":724,"children":725},{"style":444},[726],{"type":24,"value":679},{"type":19,"tag":98,"props":728,"children":729},{"style":467},[730],{"type":24,"value":684},{"type":19,"tag":98,"props":732,"children":733},{"style":235},[734],{"type":24,"value":623},{"type":19,"tag":98,"props":736,"children":737},{"style":467},[738],{"type":24,"value":739},"AuditLog",{"type":19,"tag":98,"props":741,"children":742},{"style":235},[743],{"type":24,"value":744},"> AuditLogs { ",{"type":19,"tag":98,"props":746,"children":747},{"style":450},[748],{"type":24,"value":703},{"type":19,"tag":98,"props":750,"children":751},{"style":235},[752],{"type":24,"value":708},{"type":19,"tag":98,"props":754,"children":755},{"style":450},[756],{"type":24,"value":713},{"type":19,"tag":98,"props":758,"children":759},{"style":235},[760],{"type":24,"value":718},{"type":19,"tag":98,"props":762,"children":764},{"class":100,"line":763},8,[765],{"type":19,"tag":98,"props":766,"children":767},{"style":235},[768],{"type":24,"value":769},"}\n",{"type":19,"tag":98,"props":771,"children":773},{"class":100,"line":772},9,[774],{"type":19,"tag":98,"props":775,"children":776},{"emptyLinePlaceholder":588},[777],{"type":24,"value":591},{"type":19,"tag":98,"props":779,"children":781},{"class":100,"line":780},10,[782,787,792,797,802,807,811,815],{"type":19,"tag":98,"props":783,"children":784},{"style":450},[785],{"type":24,"value":786},"var",{"type":19,"tag":98,"props":788,"children":789},{"style":235},[790],{"type":24,"value":791}," optionsBuilder ",{"type":19,"tag":98,"props":793,"children":794},{"style":444},[795],{"type":24,"value":796},"=",{"type":19,"tag":98,"props":798,"children":799},{"style":601},[800],{"type":24,"value":801}," new",{"type":19,"tag":98,"props":803,"children":804},{"style":467},[805],{"type":24,"value":806}," DbContextOptionsBuilder",{"type":19,"tag":98,"props":808,"children":809},{"style":235},[810],{"type":24,"value":623},{"type":19,"tag":98,"props":812,"children":813},{"style":467},[814],{"type":24,"value":628},{"type":19,"tag":98,"props":816,"children":817},{"style":235},[818],{"type":24,"value":819},">()\n",{"type":19,"tag":98,"props":821,"children":823},{"class":100,"line":822},11,[824,829,834,838,843,849,853,857,861,866,870],{"type":19,"tag":98,"props":825,"children":826},{"style":235},[827],{"type":24,"value":828},"    .",{"type":19,"tag":98,"props":830,"children":831},{"style":105},[832],{"type":24,"value":833},"UseMongoDB",{"type":19,"tag":98,"props":835,"children":836},{"style":235},[837],{"type":24,"value":464},{"type":19,"tag":98,"props":839,"children":841},{"style":840},"--shiki-default:#8DA101;--shiki-dark:#E9F284",[842],{"type":24,"value":285},{"type":19,"tag":98,"props":844,"children":846},{"style":845},"--shiki-default:#8DA101;--shiki-dark:#F1FA8C",[847],{"type":24,"value":848},"mongodb://localhost:27017/?directConnect=True",{"type":19,"tag":98,"props":850,"children":851},{"style":840},[852],{"type":24,"value":285},{"type":19,"tag":98,"props":854,"children":855},{"style":235},[856],{"type":24,"value":481},{"type":19,"tag":98,"props":858,"children":859},{"style":840},[860],{"type":24,"value":285},{"type":19,"tag":98,"props":862,"children":863},{"style":845},[864],{"type":24,"value":865},"banking",{"type":19,"tag":98,"props":867,"children":868},{"style":840},[869],{"type":24,"value":285},{"type":19,"tag":98,"props":871,"children":872},{"style":235},[873],{"type":24,"value":510},{"type":19,"tag":98,"props":875,"children":877},{"class":100,"line":876},12,[878],{"type":19,"tag":98,"props":879,"children":880},{"emptyLinePlaceholder":588},[881],{"type":24,"value":591},{"type":19,"tag":98,"props":883,"children":885},{"class":100,"line":884},13,[886,891,896,901,905,909,913,918,924],{"type":19,"tag":98,"props":887,"children":888},{"style":601},[889],{"type":24,"value":890},"using",{"type":19,"tag":98,"props":892,"children":893},{"style":450},[894],{"type":24,"value":895}," var",{"type":19,"tag":98,"props":897,"children":898},{"style":235},[899],{"type":24,"value":900}," db ",{"type":19,"tag":98,"props":902,"children":903},{"style":444},[904],{"type":24,"value":796},{"type":19,"tag":98,"props":906,"children":907},{"style":601},[908],{"type":24,"value":801},{"type":19,"tag":98,"props":910,"children":911},{"style":467},[912],{"type":24,"value":609},{"type":19,"tag":98,"props":914,"children":915},{"style":235},[916],{"type":24,"value":917},"(optionsBuilder.",{"type":19,"tag":98,"props":919,"children":921},{"style":920},"--shiki-default:#35A77C;--shiki-dark:#F8F8F2",[922],{"type":24,"value":923},"Options",{"type":19,"tag":98,"props":925,"children":926},{"style":235},[927],{"type":24,"value":510},{"type":19,"tag":20,"props":929,"children":930},{},[931,933,938],{"type":24,"value":932},"Now when we modify multiple documents in a single ",{"type":19,"tag":94,"props":934,"children":936},{"className":935},[],[937],{"type":24,"value":406},{"type":24,"value":939}," call, the provider automatically wraps them in a transaction:",{"type":19,"tag":86,"props":941,"children":943},{"className":432,"code":942,"language":434,"meta":91,"style":91},"var source = db.Accounts.First(a => a.Number == \"12345\");\nvar target = db.Accounts.First(a => a.Number == \"67890\");\n\n// Transfer funds\nsource.Balance -= 100m;\ntarget.Balance += 100m;\n\n// Automatically uses an implicit transaction because we're affecting multiple documents\ndb.SaveChanges();\n",[944],{"type":19,"tag":94,"props":945,"children":946},{"__ignoreMap":91},[947,1027,1100,1107,1116,1144,1169,1176,1184],{"type":19,"tag":98,"props":948,"children":949},{"class":100,"line":101},[950,954,959,963,968,973,977,982,986,990,995,1000,1005,1010,1014,1019,1023],{"type":19,"tag":98,"props":951,"children":952},{"style":450},[953],{"type":24,"value":786},{"type":19,"tag":98,"props":955,"children":956},{"style":235},[957],{"type":24,"value":958}," source ",{"type":19,"tag":98,"props":960,"children":961},{"style":444},[962],{"type":24,"value":796},{"type":19,"tag":98,"props":964,"children":965},{"style":235},[966],{"type":24,"value":967}," db.",{"type":19,"tag":98,"props":969,"children":970},{"style":920},[971],{"type":24,"value":972},"Accounts",{"type":19,"tag":98,"props":974,"children":975},{"style":235},[976],{"type":24,"value":244},{"type":19,"tag":98,"props":978,"children":979},{"style":105},[980],{"type":24,"value":981},"First",{"type":19,"tag":98,"props":983,"children":984},{"style":235},[985],{"type":24,"value":464},{"type":19,"tag":98,"props":987,"children":988},{"style":473},[989],{"type":24,"value":162},{"type":19,"tag":98,"props":991,"children":992},{"style":444},[993],{"type":24,"value":994}," =>",{"type":19,"tag":98,"props":996,"children":997},{"style":235},[998],{"type":24,"value":999}," a.",{"type":19,"tag":98,"props":1001,"children":1002},{"style":920},[1003],{"type":24,"value":1004},"Number",{"type":19,"tag":98,"props":1006,"children":1007},{"style":444},[1008],{"type":24,"value":1009}," ==",{"type":19,"tag":98,"props":1011,"children":1012},{"style":840},[1013],{"type":24,"value":275},{"type":19,"tag":98,"props":1015,"children":1016},{"style":845},[1017],{"type":24,"value":1018},"12345",{"type":19,"tag":98,"props":1020,"children":1021},{"style":840},[1022],{"type":24,"value":285},{"type":19,"tag":98,"props":1024,"children":1025},{"style":235},[1026],{"type":24,"value":510},{"type":19,"tag":98,"props":1028,"children":1029},{"class":100,"line":257},[1030,1034,1039,1043,1047,1051,1055,1059,1063,1067,1071,1075,1079,1083,1087,1092,1096],{"type":19,"tag":98,"props":1031,"children":1032},{"style":450},[1033],{"type":24,"value":786},{"type":19,"tag":98,"props":1035,"children":1036},{"style":235},[1037],{"type":24,"value":1038}," target ",{"type":19,"tag":98,"props":1040,"children":1041},{"style":444},[1042],{"type":24,"value":796},{"type":19,"tag":98,"props":1044,"children":1045},{"style":235},[1046],{"type":24,"value":967},{"type":19,"tag":98,"props":1048,"children":1049},{"style":920},[1050],{"type":24,"value":972},{"type":19,"tag":98,"props":1052,"children":1053},{"style":235},[1054],{"type":24,"value":244},{"type":19,"tag":98,"props":1056,"children":1057},{"style":105},[1058],{"type":24,"value":981},{"type":19,"tag":98,"props":1060,"children":1061},{"style":235},[1062],{"type":24,"value":464},{"type":19,"tag":98,"props":1064,"children":1065},{"style":473},[1066],{"type":24,"value":162},{"type":19,"tag":98,"props":1068,"children":1069},{"style":444},[1070],{"type":24,"value":994},{"type":19,"tag":98,"props":1072,"children":1073},{"style":235},[1074],{"type":24,"value":999},{"type":19,"tag":98,"props":1076,"children":1077},{"style":920},[1078],{"type":24,"value":1004},{"type":19,"tag":98,"props":1080,"children":1081},{"style":444},[1082],{"type":24,"value":1009},{"type":19,"tag":98,"props":1084,"children":1085},{"style":840},[1086],{"type":24,"value":275},{"type":19,"tag":98,"props":1088,"children":1089},{"style":845},[1090],{"type":24,"value":1091},"67890",{"type":19,"tag":98,"props":1093,"children":1094},{"style":840},[1095],{"type":24,"value":285},{"type":19,"tag":98,"props":1097,"children":1098},{"style":235},[1099],{"type":24,"value":510},{"type":19,"tag":98,"props":1101,"children":1102},{"class":100,"line":293},[1103],{"type":19,"tag":98,"props":1104,"children":1105},{"emptyLinePlaceholder":588},[1106],{"type":24,"value":591},{"type":19,"tag":98,"props":1108,"children":1109},{"class":100,"line":347},[1110],{"type":19,"tag":98,"props":1111,"children":1113},{"style":1112},"--shiki-default:#939F91;--shiki-default-font-style:italic;--shiki-dark:#6272A4;--shiki-dark-font-style:inherit",[1114],{"type":24,"value":1115},"// Transfer funds\n",{"type":19,"tag":98,"props":1117,"children":1118},{"class":100,"line":664},[1119,1124,1129,1134,1139],{"type":19,"tag":98,"props":1120,"children":1121},{"style":235},[1122],{"type":24,"value":1123},"source.",{"type":19,"tag":98,"props":1125,"children":1126},{"style":920},[1127],{"type":24,"value":1128},"Balance",{"type":19,"tag":98,"props":1130,"children":1131},{"style":444},[1132],{"type":24,"value":1133}," -=",{"type":19,"tag":98,"props":1135,"children":1136},{"style":204},[1137],{"type":24,"value":1138}," 100m",{"type":19,"tag":98,"props":1140,"children":1141},{"style":235},[1142],{"type":24,"value":1143},";\n",{"type":19,"tag":98,"props":1145,"children":1146},{"class":100,"line":673},[1147,1152,1156,1161,1165],{"type":19,"tag":98,"props":1148,"children":1149},{"style":235},[1150],{"type":24,"value":1151},"target.",{"type":19,"tag":98,"props":1153,"children":1154},{"style":920},[1155],{"type":24,"value":1128},{"type":19,"tag":98,"props":1157,"children":1158},{"style":444},[1159],{"type":24,"value":1160}," +=",{"type":19,"tag":98,"props":1162,"children":1163},{"style":204},[1164],{"type":24,"value":1138},{"type":19,"tag":98,"props":1166,"children":1167},{"style":235},[1168],{"type":24,"value":1143},{"type":19,"tag":98,"props":1170,"children":1171},{"class":100,"line":721},[1172],{"type":19,"tag":98,"props":1173,"children":1174},{"emptyLinePlaceholder":588},[1175],{"type":24,"value":591},{"type":19,"tag":98,"props":1177,"children":1178},{"class":100,"line":763},[1179],{"type":19,"tag":98,"props":1180,"children":1181},{"style":1112},[1182],{"type":24,"value":1183},"// Automatically uses an implicit transaction because we're affecting multiple documents\n",{"type":19,"tag":98,"props":1185,"children":1186},{"class":100,"line":772},[1187,1192,1196],{"type":19,"tag":98,"props":1188,"children":1189},{"style":235},[1190],{"type":24,"value":1191},"db.",{"type":19,"tag":98,"props":1193,"children":1194},{"style":105},[1195],{"type":24,"value":406},{"type":19,"tag":98,"props":1197,"children":1198},{"style":235},[1199],{"type":24,"value":1200},"();\n",{"type":19,"tag":20,"props":1202,"children":1203},{},[1204],{"type":24,"value":1205},"The provider detects that two documents are being affected and automatically creates a transaction to ensure both balance updates succeed or fail together.",{"type":19,"tag":74,"props":1207,"children":1209},{"id":1208},"explicit-transactions",[1210],{"type":24,"value":1211},"Explicit transactions",{"type":19,"tag":20,"props":1213,"children":1214},{},[1215],{"type":24,"value":1216},"Explicit transactions give you complete control over transaction boundaries and options. This is useful when you need to:",{"type":19,"tag":1218,"props":1219,"children":1220},"ul",{},[1221,1234,1239,1244],{"type":19,"tag":1222,"props":1223,"children":1224},"li",{},[1225,1227,1232],{"type":24,"value":1226},"Include multiple ",{"type":19,"tag":94,"props":1228,"children":1230},{"className":1229},[],[1231],{"type":24,"value":406},{"type":24,"value":1233}," calls in one transaction",{"type":19,"tag":1222,"props":1235,"children":1236},{},[1237],{"type":24,"value":1238},"Mix database operations with non-database operations",{"type":19,"tag":1222,"props":1240,"children":1241},{},[1242],{"type":24,"value":1243},"Handle complex business logic that spans multiple steps",{"type":19,"tag":1222,"props":1245,"children":1246},{},[1247],{"type":24,"value":1248},"Explicitly control on whether to commit or rollback",{"type":19,"tag":20,"props":1250,"children":1251},{},[1252],{"type":24,"value":1253},"Here's the same bank transfer operation using an explicit transaction (and this time using async):",{"type":19,"tag":86,"props":1255,"children":1257},{"className":432,"code":1256,"language":434,"meta":91,"style":91},"// Start an explicit transaction\nawait using var transaction = await db.Database.BeginTransactionAsync();\n\ntry\n{\n    var source = await db.Accounts.FirstAsync(a => a.Number == \"12345\");\n    var target = await db.Accounts.FirstAsync(a => a.Number == \"67890\");\n\n    // Check if sufficient funds\n    if (source.Balance \u003C 100m)\n        throw new InvalidOperationException(\"Insufficient funds\");\n\n    Console.WriteLine($\"Withdrawing from {source.Number}\");\n    source.Balance -= 100m;\n    await db.SaveChangesAsync();\n\n    Console.WriteLine($\"Depositing to {target.Number}\");\n    target.Balance += 100m;\n    await db.SaveChangesAsync();\n\n    await transaction.CommitAsync();\n    Console.WriteLine(\"Transfer completed successfully\");\n}\ncatch (Exception ex)\n{\n    // Something went wrong, rollback\n    await transaction.RollbackAsync();\n    Console.WriteLine($\"Transfer failed: {ex.Message}\");\n    throw;\n}\n",[1258],{"type":19,"tag":94,"props":1259,"children":1260},{"__ignoreMap":91},[1261,1269,1322,1329,1337,1344,1421,1496,1503,1511,1541,1579,1586,1646,1671,1692,1700,1754,1779,1799,1807,1829,1862,1870,1894,1902,1911,1932,1987,2000],{"type":19,"tag":98,"props":1262,"children":1263},{"class":100,"line":101},[1264],{"type":19,"tag":98,"props":1265,"children":1266},{"style":1112},[1267],{"type":24,"value":1268},"// Start an explicit transaction\n",{"type":19,"tag":98,"props":1270,"children":1271},{"class":100,"line":257},[1272,1277,1282,1286,1291,1295,1300,1304,1309,1313,1318],{"type":19,"tag":98,"props":1273,"children":1274},{"style":601},[1275],{"type":24,"value":1276},"await",{"type":19,"tag":98,"props":1278,"children":1279},{"style":601},[1280],{"type":24,"value":1281}," using",{"type":19,"tag":98,"props":1283,"children":1284},{"style":450},[1285],{"type":24,"value":895},{"type":19,"tag":98,"props":1287,"children":1288},{"style":235},[1289],{"type":24,"value":1290}," transaction ",{"type":19,"tag":98,"props":1292,"children":1293},{"style":444},[1294],{"type":24,"value":796},{"type":19,"tag":98,"props":1296,"children":1297},{"style":601},[1298],{"type":24,"value":1299}," await",{"type":19,"tag":98,"props":1301,"children":1302},{"style":235},[1303],{"type":24,"value":967},{"type":19,"tag":98,"props":1305,"children":1306},{"style":920},[1307],{"type":24,"value":1308},"Database",{"type":19,"tag":98,"props":1310,"children":1311},{"style":235},[1312],{"type":24,"value":244},{"type":19,"tag":98,"props":1314,"children":1315},{"style":105},[1316],{"type":24,"value":1317},"BeginTransactionAsync",{"type":19,"tag":98,"props":1319,"children":1320},{"style":235},[1321],{"type":24,"value":1200},{"type":19,"tag":98,"props":1323,"children":1324},{"class":100,"line":293},[1325],{"type":19,"tag":98,"props":1326,"children":1327},{"emptyLinePlaceholder":588},[1328],{"type":24,"value":591},{"type":19,"tag":98,"props":1330,"children":1331},{"class":100,"line":347},[1332],{"type":19,"tag":98,"props":1333,"children":1334},{"style":601},[1335],{"type":24,"value":1336},"try\n",{"type":19,"tag":98,"props":1338,"children":1339},{"class":100,"line":664},[1340],{"type":19,"tag":98,"props":1341,"children":1342},{"style":235},[1343],{"type":24,"value":670},{"type":19,"tag":98,"props":1345,"children":1346},{"class":100,"line":673},[1347,1352,1356,1360,1364,1368,1372,1376,1381,1385,1389,1393,1397,1401,1405,1409,1413,1417],{"type":19,"tag":98,"props":1348,"children":1349},{"style":450},[1350],{"type":24,"value":1351},"    var",{"type":19,"tag":98,"props":1353,"children":1354},{"style":235},[1355],{"type":24,"value":958},{"type":19,"tag":98,"props":1357,"children":1358},{"style":444},[1359],{"type":24,"value":796},{"type":19,"tag":98,"props":1361,"children":1362},{"style":601},[1363],{"type":24,"value":1299},{"type":19,"tag":98,"props":1365,"children":1366},{"style":235},[1367],{"type":24,"value":967},{"type":19,"tag":98,"props":1369,"children":1370},{"style":920},[1371],{"type":24,"value":972},{"type":19,"tag":98,"props":1373,"children":1374},{"style":235},[1375],{"type":24,"value":244},{"type":19,"tag":98,"props":1377,"children":1378},{"style":105},[1379],{"type":24,"value":1380},"FirstAsync",{"type":19,"tag":98,"props":1382,"children":1383},{"style":235},[1384],{"type":24,"value":464},{"type":19,"tag":98,"props":1386,"children":1387},{"style":473},[1388],{"type":24,"value":162},{"type":19,"tag":98,"props":1390,"children":1391},{"style":444},[1392],{"type":24,"value":994},{"type":19,"tag":98,"props":1394,"children":1395},{"style":235},[1396],{"type":24,"value":999},{"type":19,"tag":98,"props":1398,"children":1399},{"style":920},[1400],{"type":24,"value":1004},{"type":19,"tag":98,"props":1402,"children":1403},{"style":444},[1404],{"type":24,"value":1009},{"type":19,"tag":98,"props":1406,"children":1407},{"style":840},[1408],{"type":24,"value":275},{"type":19,"tag":98,"props":1410,"children":1411},{"style":845},[1412],{"type":24,"value":1018},{"type":19,"tag":98,"props":1414,"children":1415},{"style":840},[1416],{"type":24,"value":285},{"type":19,"tag":98,"props":1418,"children":1419},{"style":235},[1420],{"type":24,"value":510},{"type":19,"tag":98,"props":1422,"children":1423},{"class":100,"line":721},[1424,1428,1432,1436,1440,1444,1448,1452,1456,1460,1464,1468,1472,1476,1480,1484,1488,1492],{"type":19,"tag":98,"props":1425,"children":1426},{"style":450},[1427],{"type":24,"value":1351},{"type":19,"tag":98,"props":1429,"children":1430},{"style":235},[1431],{"type":24,"value":1038},{"type":19,"tag":98,"props":1433,"children":1434},{"style":444},[1435],{"type":24,"value":796},{"type":19,"tag":98,"props":1437,"children":1438},{"style":601},[1439],{"type":24,"value":1299},{"type":19,"tag":98,"props":1441,"children":1442},{"style":235},[1443],{"type":24,"value":967},{"type":19,"tag":98,"props":1445,"children":1446},{"style":920},[1447],{"type":24,"value":972},{"type":19,"tag":98,"props":1449,"children":1450},{"style":235},[1451],{"type":24,"value":244},{"type":19,"tag":98,"props":1453,"children":1454},{"style":105},[1455],{"type":24,"value":1380},{"type":19,"tag":98,"props":1457,"children":1458},{"style":235},[1459],{"type":24,"value":464},{"type":19,"tag":98,"props":1461,"children":1462},{"style":473},[1463],{"type":24,"value":162},{"type":19,"tag":98,"props":1465,"children":1466},{"style":444},[1467],{"type":24,"value":994},{"type":19,"tag":98,"props":1469,"children":1470},{"style":235},[1471],{"type":24,"value":999},{"type":19,"tag":98,"props":1473,"children":1474},{"style":920},[1475],{"type":24,"value":1004},{"type":19,"tag":98,"props":1477,"children":1478},{"style":444},[1479],{"type":24,"value":1009},{"type":19,"tag":98,"props":1481,"children":1482},{"style":840},[1483],{"type":24,"value":275},{"type":19,"tag":98,"props":1485,"children":1486},{"style":845},[1487],{"type":24,"value":1091},{"type":19,"tag":98,"props":1489,"children":1490},{"style":840},[1491],{"type":24,"value":285},{"type":19,"tag":98,"props":1493,"children":1494},{"style":235},[1495],{"type":24,"value":510},{"type":19,"tag":98,"props":1497,"children":1498},{"class":100,"line":763},[1499],{"type":19,"tag":98,"props":1500,"children":1501},{"emptyLinePlaceholder":588},[1502],{"type":24,"value":591},{"type":19,"tag":98,"props":1504,"children":1505},{"class":100,"line":772},[1506],{"type":19,"tag":98,"props":1507,"children":1508},{"style":1112},[1509],{"type":24,"value":1510},"    // Check if sufficient funds\n",{"type":19,"tag":98,"props":1512,"children":1513},{"class":100,"line":780},[1514,1519,1524,1528,1533,1537],{"type":19,"tag":98,"props":1515,"children":1516},{"style":601},[1517],{"type":24,"value":1518},"    if",{"type":19,"tag":98,"props":1520,"children":1521},{"style":235},[1522],{"type":24,"value":1523}," (source.",{"type":19,"tag":98,"props":1525,"children":1526},{"style":920},[1527],{"type":24,"value":1128},{"type":19,"tag":98,"props":1529,"children":1530},{"style":444},[1531],{"type":24,"value":1532}," \u003C",{"type":19,"tag":98,"props":1534,"children":1535},{"style":204},[1536],{"type":24,"value":1138},{"type":19,"tag":98,"props":1538,"children":1539},{"style":235},[1540],{"type":24,"value":661},{"type":19,"tag":98,"props":1542,"children":1543},{"class":100,"line":822},[1544,1549,1553,1558,1562,1566,1571,1575],{"type":19,"tag":98,"props":1545,"children":1546},{"style":601},[1547],{"type":24,"value":1548},"        throw",{"type":19,"tag":98,"props":1550,"children":1551},{"style":601},[1552],{"type":24,"value":801},{"type":19,"tag":98,"props":1554,"children":1555},{"style":467},[1556],{"type":24,"value":1557}," InvalidOperationException",{"type":19,"tag":98,"props":1559,"children":1560},{"style":235},[1561],{"type":24,"value":464},{"type":19,"tag":98,"props":1563,"children":1564},{"style":840},[1565],{"type":24,"value":285},{"type":19,"tag":98,"props":1567,"children":1568},{"style":845},[1569],{"type":24,"value":1570},"Insufficient funds",{"type":19,"tag":98,"props":1572,"children":1573},{"style":840},[1574],{"type":24,"value":285},{"type":19,"tag":98,"props":1576,"children":1577},{"style":235},[1578],{"type":24,"value":510},{"type":19,"tag":98,"props":1580,"children":1581},{"class":100,"line":876},[1582],{"type":19,"tag":98,"props":1583,"children":1584},{"emptyLinePlaceholder":588},[1585],{"type":24,"value":591},{"type":19,"tag":98,"props":1587,"children":1588},{"class":100,"line":884},[1589,1594,1599,1603,1608,1613,1619,1624,1629,1633,1638,1642],{"type":19,"tag":98,"props":1590,"children":1591},{"style":235},[1592],{"type":24,"value":1593},"    Console.",{"type":19,"tag":98,"props":1595,"children":1596},{"style":105},[1597],{"type":24,"value":1598},"WriteLine",{"type":19,"tag":98,"props":1600,"children":1601},{"style":235},[1602],{"type":24,"value":464},{"type":19,"tag":98,"props":1604,"children":1605},{"style":840},[1606],{"type":24,"value":1607},"$\"",{"type":19,"tag":98,"props":1609,"children":1610},{"style":845},[1611],{"type":24,"value":1612},"Withdrawing from ",{"type":19,"tag":98,"props":1614,"children":1616},{"style":1615},"--shiki-default:#DFA000;--shiki-dark:#FF79C6",[1617],{"type":24,"value":1618},"{",{"type":19,"tag":98,"props":1620,"children":1621},{"style":235},[1622],{"type":24,"value":1623},"source",{"type":19,"tag":98,"props":1625,"children":1627},{"style":1626},"--shiki-default:#5C6A72;--shiki-dark:#F1FA8C",[1628],{"type":24,"value":244},{"type":19,"tag":98,"props":1630,"children":1631},{"style":920},[1632],{"type":24,"value":1004},{"type":19,"tag":98,"props":1634,"children":1635},{"style":1615},[1636],{"type":24,"value":1637},"}",{"type":19,"tag":98,"props":1639,"children":1640},{"style":840},[1641],{"type":24,"value":285},{"type":19,"tag":98,"props":1643,"children":1644},{"style":235},[1645],{"type":24,"value":510},{"type":19,"tag":98,"props":1647,"children":1649},{"class":100,"line":1648},14,[1650,1655,1659,1663,1667],{"type":19,"tag":98,"props":1651,"children":1652},{"style":235},[1653],{"type":24,"value":1654},"    source.",{"type":19,"tag":98,"props":1656,"children":1657},{"style":920},[1658],{"type":24,"value":1128},{"type":19,"tag":98,"props":1660,"children":1661},{"style":444},[1662],{"type":24,"value":1133},{"type":19,"tag":98,"props":1664,"children":1665},{"style":204},[1666],{"type":24,"value":1138},{"type":19,"tag":98,"props":1668,"children":1669},{"style":235},[1670],{"type":24,"value":1143},{"type":19,"tag":98,"props":1672,"children":1674},{"class":100,"line":1673},15,[1675,1680,1684,1688],{"type":19,"tag":98,"props":1676,"children":1677},{"style":601},[1678],{"type":24,"value":1679},"    await",{"type":19,"tag":98,"props":1681,"children":1682},{"style":235},[1683],{"type":24,"value":967},{"type":19,"tag":98,"props":1685,"children":1686},{"style":105},[1687],{"type":24,"value":414},{"type":19,"tag":98,"props":1689,"children":1690},{"style":235},[1691],{"type":24,"value":1200},{"type":19,"tag":98,"props":1693,"children":1695},{"class":100,"line":1694},16,[1696],{"type":19,"tag":98,"props":1697,"children":1698},{"emptyLinePlaceholder":588},[1699],{"type":24,"value":591},{"type":19,"tag":98,"props":1701,"children":1703},{"class":100,"line":1702},17,[1704,1708,1712,1716,1720,1725,1729,1734,1738,1742,1746,1750],{"type":19,"tag":98,"props":1705,"children":1706},{"style":235},[1707],{"type":24,"value":1593},{"type":19,"tag":98,"props":1709,"children":1710},{"style":105},[1711],{"type":24,"value":1598},{"type":19,"tag":98,"props":1713,"children":1714},{"style":235},[1715],{"type":24,"value":464},{"type":19,"tag":98,"props":1717,"children":1718},{"style":840},[1719],{"type":24,"value":1607},{"type":19,"tag":98,"props":1721,"children":1722},{"style":845},[1723],{"type":24,"value":1724},"Depositing to ",{"type":19,"tag":98,"props":1726,"children":1727},{"style":1615},[1728],{"type":24,"value":1618},{"type":19,"tag":98,"props":1730,"children":1731},{"style":235},[1732],{"type":24,"value":1733},"target",{"type":19,"tag":98,"props":1735,"children":1736},{"style":1626},[1737],{"type":24,"value":244},{"type":19,"tag":98,"props":1739,"children":1740},{"style":920},[1741],{"type":24,"value":1004},{"type":19,"tag":98,"props":1743,"children":1744},{"style":1615},[1745],{"type":24,"value":1637},{"type":19,"tag":98,"props":1747,"children":1748},{"style":840},[1749],{"type":24,"value":285},{"type":19,"tag":98,"props":1751,"children":1752},{"style":235},[1753],{"type":24,"value":510},{"type":19,"tag":98,"props":1755,"children":1757},{"class":100,"line":1756},18,[1758,1763,1767,1771,1775],{"type":19,"tag":98,"props":1759,"children":1760},{"style":235},[1761],{"type":24,"value":1762},"    target.",{"type":19,"tag":98,"props":1764,"children":1765},{"style":920},[1766],{"type":24,"value":1128},{"type":19,"tag":98,"props":1768,"children":1769},{"style":444},[1770],{"type":24,"value":1160},{"type":19,"tag":98,"props":1772,"children":1773},{"style":204},[1774],{"type":24,"value":1138},{"type":19,"tag":98,"props":1776,"children":1777},{"style":235},[1778],{"type":24,"value":1143},{"type":19,"tag":98,"props":1780,"children":1782},{"class":100,"line":1781},19,[1783,1787,1791,1795],{"type":19,"tag":98,"props":1784,"children":1785},{"style":601},[1786],{"type":24,"value":1679},{"type":19,"tag":98,"props":1788,"children":1789},{"style":235},[1790],{"type":24,"value":967},{"type":19,"tag":98,"props":1792,"children":1793},{"style":105},[1794],{"type":24,"value":414},{"type":19,"tag":98,"props":1796,"children":1797},{"style":235},[1798],{"type":24,"value":1200},{"type":19,"tag":98,"props":1800,"children":1802},{"class":100,"line":1801},20,[1803],{"type":19,"tag":98,"props":1804,"children":1805},{"emptyLinePlaceholder":588},[1806],{"type":24,"value":591},{"type":19,"tag":98,"props":1808,"children":1810},{"class":100,"line":1809},21,[1811,1815,1820,1825],{"type":19,"tag":98,"props":1812,"children":1813},{"style":601},[1814],{"type":24,"value":1679},{"type":19,"tag":98,"props":1816,"children":1817},{"style":235},[1818],{"type":24,"value":1819}," transaction.",{"type":19,"tag":98,"props":1821,"children":1822},{"style":105},[1823],{"type":24,"value":1824},"CommitAsync",{"type":19,"tag":98,"props":1826,"children":1827},{"style":235},[1828],{"type":24,"value":1200},{"type":19,"tag":98,"props":1830,"children":1832},{"class":100,"line":1831},22,[1833,1837,1841,1845,1849,1854,1858],{"type":19,"tag":98,"props":1834,"children":1835},{"style":235},[1836],{"type":24,"value":1593},{"type":19,"tag":98,"props":1838,"children":1839},{"style":105},[1840],{"type":24,"value":1598},{"type":19,"tag":98,"props":1842,"children":1843},{"style":235},[1844],{"type":24,"value":464},{"type":19,"tag":98,"props":1846,"children":1847},{"style":840},[1848],{"type":24,"value":285},{"type":19,"tag":98,"props":1850,"children":1851},{"style":845},[1852],{"type":24,"value":1853},"Transfer completed successfully",{"type":19,"tag":98,"props":1855,"children":1856},{"style":840},[1857],{"type":24,"value":285},{"type":19,"tag":98,"props":1859,"children":1860},{"style":235},[1861],{"type":24,"value":510},{"type":19,"tag":98,"props":1863,"children":1865},{"class":100,"line":1864},23,[1866],{"type":19,"tag":98,"props":1867,"children":1868},{"style":235},[1869],{"type":24,"value":769},{"type":19,"tag":98,"props":1871,"children":1873},{"class":100,"line":1872},24,[1874,1879,1884,1889],{"type":19,"tag":98,"props":1875,"children":1876},{"style":601},[1877],{"type":24,"value":1878},"catch",{"type":19,"tag":98,"props":1880,"children":1881},{"style":235},[1882],{"type":24,"value":1883}," (",{"type":19,"tag":98,"props":1885,"children":1886},{"style":467},[1887],{"type":24,"value":1888},"Exception",{"type":19,"tag":98,"props":1890,"children":1891},{"style":235},[1892],{"type":24,"value":1893}," ex)\n",{"type":19,"tag":98,"props":1895,"children":1897},{"class":100,"line":1896},25,[1898],{"type":19,"tag":98,"props":1899,"children":1900},{"style":235},[1901],{"type":24,"value":670},{"type":19,"tag":98,"props":1903,"children":1905},{"class":100,"line":1904},26,[1906],{"type":19,"tag":98,"props":1907,"children":1908},{"style":1112},[1909],{"type":24,"value":1910},"    // Something went wrong, rollback\n",{"type":19,"tag":98,"props":1912,"children":1914},{"class":100,"line":1913},27,[1915,1919,1923,1928],{"type":19,"tag":98,"props":1916,"children":1917},{"style":601},[1918],{"type":24,"value":1679},{"type":19,"tag":98,"props":1920,"children":1921},{"style":235},[1922],{"type":24,"value":1819},{"type":19,"tag":98,"props":1924,"children":1925},{"style":105},[1926],{"type":24,"value":1927},"RollbackAsync",{"type":19,"tag":98,"props":1929,"children":1930},{"style":235},[1931],{"type":24,"value":1200},{"type":19,"tag":98,"props":1933,"children":1935},{"class":100,"line":1934},28,[1936,1940,1944,1948,1952,1957,1961,1966,1970,1975,1979,1983],{"type":19,"tag":98,"props":1937,"children":1938},{"style":235},[1939],{"type":24,"value":1593},{"type":19,"tag":98,"props":1941,"children":1942},{"style":105},[1943],{"type":24,"value":1598},{"type":19,"tag":98,"props":1945,"children":1946},{"style":235},[1947],{"type":24,"value":464},{"type":19,"tag":98,"props":1949,"children":1950},{"style":840},[1951],{"type":24,"value":1607},{"type":19,"tag":98,"props":1953,"children":1954},{"style":845},[1955],{"type":24,"value":1956},"Transfer failed: ",{"type":19,"tag":98,"props":1958,"children":1959},{"style":1615},[1960],{"type":24,"value":1618},{"type":19,"tag":98,"props":1962,"children":1963},{"style":235},[1964],{"type":24,"value":1965},"ex",{"type":19,"tag":98,"props":1967,"children":1968},{"style":1626},[1969],{"type":24,"value":244},{"type":19,"tag":98,"props":1971,"children":1972},{"style":920},[1973],{"type":24,"value":1974},"Message",{"type":19,"tag":98,"props":1976,"children":1977},{"style":1615},[1978],{"type":24,"value":1637},{"type":19,"tag":98,"props":1980,"children":1981},{"style":840},[1982],{"type":24,"value":285},{"type":19,"tag":98,"props":1984,"children":1985},{"style":235},[1986],{"type":24,"value":510},{"type":19,"tag":98,"props":1988,"children":1990},{"class":100,"line":1989},29,[1991,1996],{"type":19,"tag":98,"props":1992,"children":1993},{"style":601},[1994],{"type":24,"value":1995},"    throw",{"type":19,"tag":98,"props":1997,"children":1998},{"style":235},[1999],{"type":24,"value":1143},{"type":19,"tag":98,"props":2001,"children":2003},{"class":100,"line":2002},30,[2004],{"type":19,"tag":98,"props":2005,"children":2006},{"style":235},[2007],{"type":24,"value":769},{"type":19,"tag":20,"props":2009,"children":2010},{},[2011,2013,2018,2019,2024],{"type":24,"value":2012},"Explicit transactions let you span multiple ",{"type":19,"tag":94,"props":2014,"children":2016},{"className":2015},[],[2017],{"type":24,"value":406},{"type":24,"value":408},{"type":19,"tag":94,"props":2020,"children":2022},{"className":2021},[],[2023],{"type":24,"value":414},{"type":24,"value":2025},") calls and include your own validation logic, all within a single atomic operation.",{"type":19,"tag":74,"props":2027,"children":2029},{"id":2028},"ambient-transactions",[2030],{"type":24,"value":2031},"Ambient transactions",{"type":19,"tag":20,"props":2033,"children":2034},{},[2035,2037,2044],{"type":24,"value":2036},"Ambient transactions are a feature in the .NET CLR whereby ",{"type":19,"tag":162,"props":2038,"children":2041},{"href":2039,"rel":2040},"https://learn.microsoft.com/en-us/dotnet/api/system.transactions.transaction?view=net-9.0",[166],[2042],{"type":24,"value":2043},"System.Transactions.Transaction.Current",{"type":24,"value":2045}," provides a way to coordinate a transaction across technologies.",{"type":19,"tag":20,"props":2047,"children":2048},{},[2049,2051,2057],{"type":24,"value":2050},"Due to the complicated nature of ",{"type":19,"tag":94,"props":2052,"children":2054},{"className":2053},[],[2055],{"type":24,"value":2056},"System.Transactions",{"type":24,"value":2058}," and the difficulties in using it correctly with async/await and multi-threading, we have decided instead to encourage use of our explicit transaction support, which also allows you to coordinate work across providers but in a more explicit manner.",{"type":19,"tag":51,"props":2060,"children":2062},{"id":2061},"implementation-considerations",[2063],{"type":24,"value":2064},"Implementation considerations",{"type":19,"tag":74,"props":2066,"children":2068},{"id":2067},"when-to-use-implicit-vs-explicit",[2069],{"type":24,"value":2070},"When to use implicit vs explicit",{"type":19,"tag":20,"props":2072,"children":2073},{},[2074],{"type":24,"value":2075},"Choosing between implicit and explicit transactions depends on your specific use case. Here's a comparison to help you decide:",{"type":19,"tag":2077,"props":2078,"children":2079},"table",{},[2080,2104],{"type":19,"tag":2081,"props":2082,"children":2083},"thead",{},[2084],{"type":19,"tag":2085,"props":2086,"children":2087},"tr",{},[2088,2094,2099],{"type":19,"tag":2089,"props":2090,"children":2091},"th",{},[2092],{"type":24,"value":2093},"Scenario",{"type":19,"tag":2089,"props":2095,"children":2096},{},[2097],{"type":24,"value":2098},"Implicit Transactions",{"type":19,"tag":2089,"props":2100,"children":2101},{},[2102],{"type":24,"value":2103},"Explicit Transactions",{"type":19,"tag":2105,"props":2106,"children":2107},"tbody",{},[2108,2137,2165,2186],{"type":19,"tag":2085,"props":2109,"children":2110},{},[2111,2127,2132],{"type":19,"tag":2112,"props":2113,"children":2114},"td",{},[2115],{"type":19,"tag":63,"props":2116,"children":2117},{},[2118,2120,2125],{"type":24,"value":2119},"Single ",{"type":19,"tag":94,"props":2121,"children":2123},{"className":2122},[],[2124],{"type":24,"value":406},{"type":24,"value":2126}," call",{"type":19,"tag":2112,"props":2128,"children":2129},{},[2130],{"type":24,"value":2131},"✅ Automatic and simple",{"type":19,"tag":2112,"props":2133,"children":2134},{},[2135],{"type":24,"value":2136},"❌ Unnecessarily complex",{"type":19,"tag":2085,"props":2138,"children":2139},{},[2140,2155,2160],{"type":19,"tag":2112,"props":2141,"children":2142},{},[2143],{"type":19,"tag":63,"props":2144,"children":2145},{},[2146,2148,2153],{"type":24,"value":2147},"Multiple ",{"type":19,"tag":94,"props":2149,"children":2151},{"className":2150},[],[2152],{"type":24,"value":406},{"type":24,"value":2154}," calls",{"type":19,"tag":2112,"props":2156,"children":2157},{},[2158],{"type":24,"value":2159},"❌ Each call is a separate transaction",{"type":19,"tag":2112,"props":2161,"children":2162},{},[2163],{"type":24,"value":2164},"✅ Spans multiple operations",{"type":19,"tag":2085,"props":2166,"children":2167},{},[2168,2176,2181],{"type":19,"tag":2112,"props":2169,"children":2170},{},[2171],{"type":19,"tag":63,"props":2172,"children":2173},{},[2174],{"type":24,"value":2175},"Error handling control",{"type":19,"tag":2112,"props":2177,"children":2178},{},[2179],{"type":24,"value":2180},"❌ Automatic rollback only",{"type":19,"tag":2112,"props":2182,"children":2183},{},[2184],{"type":24,"value":2185},"✅ Custom error handling",{"type":19,"tag":2085,"props":2187,"children":2188},{},[2189,2197,2202],{"type":19,"tag":2112,"props":2190,"children":2191},{},[2192],{"type":19,"tag":63,"props":2193,"children":2194},{},[2195],{"type":24,"value":2196},"Cross-provider steps",{"type":19,"tag":2112,"props":2198,"children":2199},{},[2200],{"type":24,"value":2201},"❌ Not supported",{"type":19,"tag":2112,"props":2203,"children":2204},{},[2205],{"type":24,"value":2206},"✅ Coordinate with other providers",{"type":19,"tag":1218,"props":2208,"children":2209},{},[2210,2226],{"type":19,"tag":1222,"props":2211,"children":2212},{},[2213,2218,2220,2225],{"type":19,"tag":63,"props":2214,"children":2215},{},[2216],{"type":24,"value":2217},"Use implicit transactions",{"type":24,"value":2219}," when you have simple multi-document operations that can be completed in a single ",{"type":19,"tag":94,"props":2221,"children":2223},{"className":2222},[],[2224],{"type":24,"value":406},{"type":24,"value":2126},{"type":19,"tag":1222,"props":2227,"children":2228},{},[2229,2234,2236,2241],{"type":19,"tag":63,"props":2230,"children":2231},{},[2232],{"type":24,"value":2233},"Use explicit transactions",{"type":24,"value":2235}," when you need multiple ",{"type":19,"tag":94,"props":2237,"children":2239},{"className":2238},[],[2240],{"type":24,"value":406},{"type":24,"value":2242}," calls, custom validation, or complex error handling",{"type":19,"tag":74,"props":2244,"children":2246},{"id":2245},"transaction-scope",[2247],{"type":24,"value":2248},"Transaction scope",{"type":19,"tag":20,"props":2250,"children":2251},{},[2252],{"type":24,"value":2253},"Starting an explicit transaction on a DbContext means that context instance can read all its own uncommitted writes, including across collections. For example:",{"type":19,"tag":86,"props":2255,"children":2257},{"className":432,"code":2256,"language":434,"meta":91,"style":91},"using var transaction = db.Database.BeginTransaction();\n\ntry\n{\n    var account = db.Accounts.First(a => a.Number == \"12345\");\n    account.Balance += 500m;\n    db.SaveChanges();\n\n    db.AuditLogs.Add(new AuditLog\n    {\n        Timestamp = DateTime.UtcNow,\n        Action = \"Deposit\",\n        Details = $\"Added 500 to account {account.Number}\"\n    });\n    db.SaveChanges();\n\n    transaction.Commit();\n}\ncatch\n{\n    transaction.Rollback();\n    throw;\n}\n",[2258],{"type":19,"tag":94,"props":2259,"children":2260},{"__ignoreMap":91},[2261,2301,2308,2315,2322,2394,2419,2435,2442,2477,2485,2511,2540,2588,2596,2611,2618,2635,2642,2650,2657,2673,2684],{"type":19,"tag":98,"props":2262,"children":2263},{"class":100,"line":101},[2264,2268,2272,2276,2280,2284,2288,2292,2297],{"type":19,"tag":98,"props":2265,"children":2266},{"style":601},[2267],{"type":24,"value":890},{"type":19,"tag":98,"props":2269,"children":2270},{"style":450},[2271],{"type":24,"value":895},{"type":19,"tag":98,"props":2273,"children":2274},{"style":235},[2275],{"type":24,"value":1290},{"type":19,"tag":98,"props":2277,"children":2278},{"style":444},[2279],{"type":24,"value":796},{"type":19,"tag":98,"props":2281,"children":2282},{"style":235},[2283],{"type":24,"value":967},{"type":19,"tag":98,"props":2285,"children":2286},{"style":920},[2287],{"type":24,"value":1308},{"type":19,"tag":98,"props":2289,"children":2290},{"style":235},[2291],{"type":24,"value":244},{"type":19,"tag":98,"props":2293,"children":2294},{"style":105},[2295],{"type":24,"value":2296},"BeginTransaction",{"type":19,"tag":98,"props":2298,"children":2299},{"style":235},[2300],{"type":24,"value":1200},{"type":19,"tag":98,"props":2302,"children":2303},{"class":100,"line":257},[2304],{"type":19,"tag":98,"props":2305,"children":2306},{"emptyLinePlaceholder":588},[2307],{"type":24,"value":591},{"type":19,"tag":98,"props":2309,"children":2310},{"class":100,"line":293},[2311],{"type":19,"tag":98,"props":2312,"children":2313},{"style":601},[2314],{"type":24,"value":1336},{"type":19,"tag":98,"props":2316,"children":2317},{"class":100,"line":347},[2318],{"type":19,"tag":98,"props":2319,"children":2320},{"style":235},[2321],{"type":24,"value":670},{"type":19,"tag":98,"props":2323,"children":2324},{"class":100,"line":664},[2325,2329,2334,2338,2342,2346,2350,2354,2358,2362,2366,2370,2374,2378,2382,2386,2390],{"type":19,"tag":98,"props":2326,"children":2327},{"style":450},[2328],{"type":24,"value":1351},{"type":19,"tag":98,"props":2330,"children":2331},{"style":235},[2332],{"type":24,"value":2333}," account ",{"type":19,"tag":98,"props":2335,"children":2336},{"style":444},[2337],{"type":24,"value":796},{"type":19,"tag":98,"props":2339,"children":2340},{"style":235},[2341],{"type":24,"value":967},{"type":19,"tag":98,"props":2343,"children":2344},{"style":920},[2345],{"type":24,"value":972},{"type":19,"tag":98,"props":2347,"children":2348},{"style":235},[2349],{"type":24,"value":244},{"type":19,"tag":98,"props":2351,"children":2352},{"style":105},[2353],{"type":24,"value":981},{"type":19,"tag":98,"props":2355,"children":2356},{"style":235},[2357],{"type":24,"value":464},{"type":19,"tag":98,"props":2359,"children":2360},{"style":473},[2361],{"type":24,"value":162},{"type":19,"tag":98,"props":2363,"children":2364},{"style":444},[2365],{"type":24,"value":994},{"type":19,"tag":98,"props":2367,"children":2368},{"style":235},[2369],{"type":24,"value":999},{"type":19,"tag":98,"props":2371,"children":2372},{"style":920},[2373],{"type":24,"value":1004},{"type":19,"tag":98,"props":2375,"children":2376},{"style":444},[2377],{"type":24,"value":1009},{"type":19,"tag":98,"props":2379,"children":2380},{"style":840},[2381],{"type":24,"value":275},{"type":19,"tag":98,"props":2383,"children":2384},{"style":845},[2385],{"type":24,"value":1018},{"type":19,"tag":98,"props":2387,"children":2388},{"style":840},[2389],{"type":24,"value":285},{"type":19,"tag":98,"props":2391,"children":2392},{"style":235},[2393],{"type":24,"value":510},{"type":19,"tag":98,"props":2395,"children":2396},{"class":100,"line":673},[2397,2402,2406,2410,2415],{"type":19,"tag":98,"props":2398,"children":2399},{"style":235},[2400],{"type":24,"value":2401},"    account.",{"type":19,"tag":98,"props":2403,"children":2404},{"style":920},[2405],{"type":24,"value":1128},{"type":19,"tag":98,"props":2407,"children":2408},{"style":444},[2409],{"type":24,"value":1160},{"type":19,"tag":98,"props":2411,"children":2412},{"style":204},[2413],{"type":24,"value":2414}," 500m",{"type":19,"tag":98,"props":2416,"children":2417},{"style":235},[2418],{"type":24,"value":1143},{"type":19,"tag":98,"props":2420,"children":2421},{"class":100,"line":721},[2422,2427,2431],{"type":19,"tag":98,"props":2423,"children":2424},{"style":235},[2425],{"type":24,"value":2426},"    db.",{"type":19,"tag":98,"props":2428,"children":2429},{"style":105},[2430],{"type":24,"value":406},{"type":19,"tag":98,"props":2432,"children":2433},{"style":235},[2434],{"type":24,"value":1200},{"type":19,"tag":98,"props":2436,"children":2437},{"class":100,"line":763},[2438],{"type":19,"tag":98,"props":2439,"children":2440},{"emptyLinePlaceholder":588},[2441],{"type":24,"value":591},{"type":19,"tag":98,"props":2443,"children":2444},{"class":100,"line":772},[2445,2449,2454,2458,2463,2467,2472],{"type":19,"tag":98,"props":2446,"children":2447},{"style":235},[2448],{"type":24,"value":2426},{"type":19,"tag":98,"props":2450,"children":2451},{"style":920},[2452],{"type":24,"value":2453},"AuditLogs",{"type":19,"tag":98,"props":2455,"children":2456},{"style":235},[2457],{"type":24,"value":244},{"type":19,"tag":98,"props":2459,"children":2460},{"style":105},[2461],{"type":24,"value":2462},"Add",{"type":19,"tag":98,"props":2464,"children":2465},{"style":235},[2466],{"type":24,"value":464},{"type":19,"tag":98,"props":2468,"children":2469},{"style":601},[2470],{"type":24,"value":2471},"new",{"type":19,"tag":98,"props":2473,"children":2474},{"style":467},[2475],{"type":24,"value":2476}," AuditLog\n",{"type":19,"tag":98,"props":2478,"children":2479},{"class":100,"line":780},[2480],{"type":19,"tag":98,"props":2481,"children":2482},{"style":235},[2483],{"type":24,"value":2484},"    {\n",{"type":19,"tag":98,"props":2486,"children":2487},{"class":100,"line":822},[2488,2493,2497,2502,2507],{"type":19,"tag":98,"props":2489,"children":2490},{"style":235},[2491],{"type":24,"value":2492},"        Timestamp ",{"type":19,"tag":98,"props":2494,"children":2495},{"style":444},[2496],{"type":24,"value":796},{"type":19,"tag":98,"props":2498,"children":2499},{"style":235},[2500],{"type":24,"value":2501}," DateTime.",{"type":19,"tag":98,"props":2503,"children":2504},{"style":920},[2505],{"type":24,"value":2506},"UtcNow",{"type":19,"tag":98,"props":2508,"children":2509},{"style":235},[2510],{"type":24,"value":290},{"type":19,"tag":98,"props":2512,"children":2513},{"class":100,"line":876},[2514,2519,2523,2527,2532,2536],{"type":19,"tag":98,"props":2515,"children":2516},{"style":235},[2517],{"type":24,"value":2518},"        Action ",{"type":19,"tag":98,"props":2520,"children":2521},{"style":444},[2522],{"type":24,"value":796},{"type":19,"tag":98,"props":2524,"children":2525},{"style":840},[2526],{"type":24,"value":275},{"type":19,"tag":98,"props":2528,"children":2529},{"style":845},[2530],{"type":24,"value":2531},"Deposit",{"type":19,"tag":98,"props":2533,"children":2534},{"style":840},[2535],{"type":24,"value":285},{"type":19,"tag":98,"props":2537,"children":2538},{"style":235},[2539],{"type":24,"value":290},{"type":19,"tag":98,"props":2541,"children":2542},{"class":100,"line":884},[2543,2548,2552,2557,2562,2566,2571,2575,2579,2583],{"type":19,"tag":98,"props":2544,"children":2545},{"style":235},[2546],{"type":24,"value":2547},"        Details ",{"type":19,"tag":98,"props":2549,"children":2550},{"style":444},[2551],{"type":24,"value":796},{"type":19,"tag":98,"props":2553,"children":2554},{"style":840},[2555],{"type":24,"value":2556}," $\"",{"type":19,"tag":98,"props":2558,"children":2559},{"style":845},[2560],{"type":24,"value":2561},"Added 500 to account ",{"type":19,"tag":98,"props":2563,"children":2564},{"style":1615},[2565],{"type":24,"value":1618},{"type":19,"tag":98,"props":2567,"children":2568},{"style":235},[2569],{"type":24,"value":2570},"account",{"type":19,"tag":98,"props":2572,"children":2573},{"style":1626},[2574],{"type":24,"value":244},{"type":19,"tag":98,"props":2576,"children":2577},{"style":920},[2578],{"type":24,"value":1004},{"type":19,"tag":98,"props":2580,"children":2581},{"style":1615},[2582],{"type":24,"value":1637},{"type":19,"tag":98,"props":2584,"children":2585},{"style":840},[2586],{"type":24,"value":2587},"\"\n",{"type":19,"tag":98,"props":2589,"children":2590},{"class":100,"line":1648},[2591],{"type":19,"tag":98,"props":2592,"children":2593},{"style":235},[2594],{"type":24,"value":2595},"    });\n",{"type":19,"tag":98,"props":2597,"children":2598},{"class":100,"line":1673},[2599,2603,2607],{"type":19,"tag":98,"props":2600,"children":2601},{"style":235},[2602],{"type":24,"value":2426},{"type":19,"tag":98,"props":2604,"children":2605},{"style":105},[2606],{"type":24,"value":406},{"type":19,"tag":98,"props":2608,"children":2609},{"style":235},[2610],{"type":24,"value":1200},{"type":19,"tag":98,"props":2612,"children":2613},{"class":100,"line":1694},[2614],{"type":19,"tag":98,"props":2615,"children":2616},{"emptyLinePlaceholder":588},[2617],{"type":24,"value":591},{"type":19,"tag":98,"props":2619,"children":2620},{"class":100,"line":1702},[2621,2626,2631],{"type":19,"tag":98,"props":2622,"children":2623},{"style":235},[2624],{"type":24,"value":2625},"    transaction.",{"type":19,"tag":98,"props":2627,"children":2628},{"style":105},[2629],{"type":24,"value":2630},"Commit",{"type":19,"tag":98,"props":2632,"children":2633},{"style":235},[2634],{"type":24,"value":1200},{"type":19,"tag":98,"props":2636,"children":2637},{"class":100,"line":1756},[2638],{"type":19,"tag":98,"props":2639,"children":2640},{"style":235},[2641],{"type":24,"value":769},{"type":19,"tag":98,"props":2643,"children":2644},{"class":100,"line":1781},[2645],{"type":19,"tag":98,"props":2646,"children":2647},{"style":601},[2648],{"type":24,"value":2649},"catch\n",{"type":19,"tag":98,"props":2651,"children":2652},{"class":100,"line":1801},[2653],{"type":19,"tag":98,"props":2654,"children":2655},{"style":235},[2656],{"type":24,"value":670},{"type":19,"tag":98,"props":2658,"children":2659},{"class":100,"line":1809},[2660,2664,2669],{"type":19,"tag":98,"props":2661,"children":2662},{"style":235},[2663],{"type":24,"value":2625},{"type":19,"tag":98,"props":2665,"children":2666},{"style":105},[2667],{"type":24,"value":2668},"Rollback",{"type":19,"tag":98,"props":2670,"children":2671},{"style":235},[2672],{"type":24,"value":1200},{"type":19,"tag":98,"props":2674,"children":2675},{"class":100,"line":1831},[2676,2680],{"type":19,"tag":98,"props":2677,"children":2678},{"style":601},[2679],{"type":24,"value":1995},{"type":19,"tag":98,"props":2681,"children":2682},{"style":235},[2683],{"type":24,"value":1143},{"type":19,"tag":98,"props":2685,"children":2686},{"class":100,"line":1864},[2687],{"type":19,"tag":98,"props":2688,"children":2689},{"style":235},[2690],{"type":24,"value":769},{"type":19,"tag":20,"props":2692,"children":2693},{},[2694,2696,2701,2703,2709],{"type":24,"value":2695},"Any read operations on different instances of your ",{"type":19,"tag":94,"props":2697,"children":2699},{"className":2698},[],[2700],{"type":24,"value":648},{"type":24,"value":2702}," will be isolated from the uncommitted writes. They cannot opt-in to the transaction via any kind of ",{"type":19,"tag":94,"props":2704,"children":2706},{"className":2705},[],[2707],{"type":24,"value":2708},"UseTransaction",{"type":24,"value":2710}," operation.",{"type":19,"tag":20,"props":2712,"children":2713},{},[2714,2716,2721,2723,2729],{"type":24,"value":2715},"You may ",{"type":19,"tag":94,"props":2717,"children":2719},{"className":2718},[],[2720],{"type":24,"value":2296},{"type":24,"value":2722}," with specific ",{"type":19,"tag":94,"props":2724,"children":2726},{"className":2725},[],[2727],{"type":24,"value":2728},"TransactionOptions",{"type":24,"value":2730}," that tailor the read preference, read concern, write concern, and max commit time.",{"type":19,"tag":74,"props":2732,"children":2734},{"id":2733},"performance-limitations",[2735],{"type":24,"value":2736},"Performance & limitations",{"type":19,"tag":20,"props":2738,"children":2739},{},[2740],{"type":24,"value":2741},"Transactions in MongoDB have some technical implications to be aware of:",{"type":19,"tag":1218,"props":2743,"children":2744},{},[2745,2755,2765,2775,2785],{"type":19,"tag":1222,"props":2746,"children":2747},{},[2748,2753],{"type":19,"tag":63,"props":2749,"children":2750},{},[2751],{"type":24,"value":2752},"Keep transactions short:",{"type":24,"value":2754}," Long-running transactions can impact cluster performance",{"type":19,"tag":1222,"props":2756,"children":2757},{},[2758,2763],{"type":19,"tag":63,"props":2759,"children":2760},{},[2761],{"type":24,"value":2762},"Limit transaction size:",{"type":24,"value":2764}," MongoDB has a 16MB limit on transaction sizes",{"type":19,"tag":1222,"props":2766,"children":2767},{},[2768,2773],{"type":19,"tag":63,"props":2769,"children":2770},{},[2771],{"type":24,"value":2772},"Consider operation order:",{"type":24,"value":2774}," Place read operations before write operations when possible",{"type":19,"tag":1222,"props":2776,"children":2777},{},[2778,2783],{"type":19,"tag":63,"props":2779,"children":2780},{},[2781],{"type":24,"value":2782},"Use write concerns wisely:",{"type":24,"value":2784}," Higher write concerns increase latency but improve durability",{"type":19,"tag":1222,"props":2786,"children":2787},{},[2788,2800],{"type":19,"tag":63,"props":2789,"children":2790},{},[2791,2793,2799],{"type":24,"value":2792},"Use ",{"type":19,"tag":94,"props":2794,"children":2796},{"className":2795},[],[2797],{"type":24,"value":2798},"db.Database.EnsureCreated()",{"type":24,"value":269},{"type":24,"value":2801}," Ensure you call this at app startup as collections cannot be created in cross-shard write transactions",{"type":19,"tag":20,"props":2803,"children":2804},{},[2805,2807,2814],{"type":24,"value":2806},"Check out the ",{"type":19,"tag":162,"props":2808,"children":2811},{"href":2809,"rel":2810},"https://www.mongodb.com/docs/manual/reference/limits/#mongodb-limit-Multi-document-Transactions",[166],[2812],{"type":24,"value":2813},"MongoDB Limits and Thresholds",{"type":24,"value":244},{"type":19,"tag":20,"props":2816,"children":2817},{},[2818],{"type":24,"value":2819},"As always, start with the defaults and aim for code clarity, then measure and optimize as appropriate. Performance optimizations are usually at the expense of clarity, and you don't want to start with wrong-optimized, hard-to-understand code.",{"type":19,"tag":20,"props":2821,"children":2822},{},[2823,2825,2832],{"type":24,"value":2824},"Also check out the ",{"type":19,"tag":162,"props":2826,"children":2829},{"href":2827,"rel":2828},"https://www.mongodb.com/docs/manual/core/transactions/",[166],[2830],{"type":24,"value":2831},"MongoDB Production Considerations for Transactions",{"type":24,"value":244},{"type":19,"tag":51,"props":2834,"children":2836},{"id":2835},"thats-a-wrap",[2837],{"type":24,"value":2838},"That's a wrap",{"type":19,"tag":20,"props":2840,"children":2841},{},[2842],{"type":24,"value":2843},"The MongoDB EF Core Provider's transaction support gives you the flexibility to choose between convenient automatic implicit transactions and powerful explicit transactions for multi-step scenarios.",{"type":19,"tag":20,"props":2845,"children":2846},{},[2847],{"type":24,"value":2848},"In summary:",{"type":19,"tag":1218,"props":2850,"children":2851},{},[2852,2866,2882,2892],{"type":19,"tag":1222,"props":2853,"children":2854},{},[2855,2859,2861],{"type":19,"tag":63,"props":2856,"children":2857},{},[2858],{"type":24,"value":395},{"type":24,"value":2860}," happen automatically today inside ",{"type":19,"tag":94,"props":2862,"children":2864},{"className":2863},[],[2865],{"type":24,"value":406},{"type":19,"tag":1222,"props":2867,"children":2868},{},[2869,2873,2875,2880],{"type":19,"tag":63,"props":2870,"children":2871},{},[2872],{"type":24,"value":1211},{"type":24,"value":2874}," let you perform multiple ",{"type":19,"tag":94,"props":2876,"children":2878},{"className":2877},[],[2879],{"type":24,"value":406},{"type":24,"value":2881}," before rolling back or committing",{"type":19,"tag":1222,"props":2883,"children":2884},{},[2885,2890],{"type":19,"tag":63,"props":2886,"children":2887},{},[2888],{"type":24,"value":2889},"Always use replica sets",{"type":24,"value":2891}," in production to provide support for transactions",{"type":19,"tag":1222,"props":2893,"children":2894},{},[2895,2900],{"type":19,"tag":63,"props":2896,"children":2897},{},[2898],{"type":24,"value":2899},"Use optimistic concurrency",{"type":24,"value":2901}," to ensure you are not writing back stale data",{"type":19,"tag":20,"props":2903,"children":2904},{},[2905,2907,2914],{"type":24,"value":2906},"You can find the ",{"type":19,"tag":162,"props":2908,"children":2911},{"href":2909,"rel":2910},"https://github.com/damieng/mongodb-efcore-examples",[166],[2912],{"type":24,"value":2913},"full source code to the samples",{"type":24,"value":2915}," over at GitHub.",{"type":19,"tag":20,"props":2917,"children":2918},{},[2919],{"type":24,"value":2920},"Enjoy!",{"type":19,"tag":20,"props":2922,"children":2923},{},[2924],{"type":24,"value":2925},"Damien",{"type":19,"tag":2927,"props":2928,"children":2929},"style",{},[2930],{"type":24,"value":2931},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":91,"searchDepth":257,"depth":257,"links":2933},[2934,2939,2944,2949],{"id":53,"depth":257,"text":56,"children":2935},[2936,2937,2938],{"id":76,"depth":293,"text":79},{"id":152,"depth":293,"text":155},{"id":356,"depth":293,"text":359},{"id":381,"depth":257,"text":384,"children":2940},[2941,2942,2943],{"id":392,"depth":293,"text":395},{"id":1208,"depth":293,"text":1211},{"id":2028,"depth":293,"text":2031},{"id":2061,"depth":257,"text":2064,"children":2945},[2946,2947,2948],{"id":2067,"depth":293,"text":2070},{"id":2245,"depth":293,"text":2248},{"id":2733,"depth":293,"text":2736},{"id":2835,"depth":257,"text":2838},"markdown","content:blog:2025:mongodb-explicit-transactions.md","content","blog/2025/mongodb-explicit-transactions.md","blog/2025/mongodb-explicit-transactions","md","/blog/2025/mongodb-explicit-transactions/",1409,0,[2960,2964,2968],{"title":2961,"date":2962,"url":2963},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/html5-video-cheatsheet/",{"title":2965,"date":2966,"url":2967},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/mongodb-queryable-encryption/",{"title":2969,"date":2970,"url":2971},"Lazy Loading with EF Core Proxies","2025-04-02","/blog/2025/ef-proxies/",[],1779224630016]