73 lines
26 KiB
HTML
73 lines
26 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||
<meta name="generator" content="VuePress 2.0.0-beta.62">
|
||
<style>
|
||
:root {
|
||
--c-bg: #fff;
|
||
}
|
||
html.dark {
|
||
--c-bg: #22272e;
|
||
}
|
||
html, body {
|
||
background-color: var(--c-bg);
|
||
}
|
||
</style>
|
||
<script>
|
||
const userMode = localStorage.getItem('vuepress-color-scheme');
|
||
const systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||
if (userMode === 'dark' || (userMode !== 'light' && systemDarkMode)) {
|
||
document.documentElement.classList.toggle('dark', true);
|
||
}
|
||
</script>
|
||
<link rel="icon" href="/favicon.jpg"><title>事务,延迟提交 | 您好, 欢迎查看 MiaoYu 文档 !</title><meta name="description" content="MiaoYu 开源项目文档网站!">
|
||
<link rel="preload" href="/docs/assets/style-961b9d5d.css" as="style"><link rel="stylesheet" href="/docs/assets/style-961b9d5d.css">
|
||
<link rel="modulepreload" href="/docs/assets/app-4f4af2d5.js"><link rel="modulepreload" href="/docs/assets/work.html-fe7c2daa.js"><link rel="modulepreload" href="/docs/assets/work.html-6d0ca231.js"><link rel="prefetch" href="/docs/assets/index.html-28072875.js" as="script"><link rel="prefetch" href="/docs/assets/code-gen.html-4397c299.js" as="script"><link rel="prefetch" href="/docs/assets/home.html-3fb3b3b2.js" as="script"><link rel="prefetch" href="/docs/assets/ioc-aop.html-0144cd72.js" as="script"><link rel="prefetch" href="/docs/assets/scheduled-tasks.html-bedcb769.js" as="script"><link rel="prefetch" href="/docs/assets/user-info.html-8578df40.js" as="script"><link rel="prefetch" href="/docs/assets/home.html-013ddfd3.js" as="script"><link rel="prefetch" href="/docs/assets/dbs.html-9052a8ef.js" as="script"><link rel="prefetch" href="/docs/assets/efcore.html-ec28f7d0.js" as="script"><link rel="prefetch" href="/docs/assets/sql.html-fe3eac11.js" as="script"><link rel="prefetch" href="/docs/assets/simple.html-54212753.js" as="script"><link rel="prefetch" href="/docs/assets/split.html-e759ef21.js" as="script"><link rel="prefetch" href="/docs/assets/client.html-f2da1493.js" as="script"><link rel="prefetch" href="/docs/assets/download.html-903adac5.js" as="script"><link rel="prefetch" href="/docs/assets/problem.html-1c845052.js" as="script"><link rel="prefetch" href="/docs/assets/api.html-caba109f.js" as="script"><link rel="prefetch" href="/docs/assets/authorize.html-37a2ba6f.js" as="script"><link rel="prefetch" href="/docs/assets/data.html-578c517a.js" as="script"><link rel="prefetch" href="/docs/assets/api-check-model.html-b5cf845e.js" as="script"><link rel="prefetch" href="/docs/assets/api-resource-cache.html-f627996b.js" as="script"><link rel="prefetch" href="/docs/assets/api-result.html-f90b60b9.js" as="script"><link rel="prefetch" href="/docs/assets/request-limit.html-79d7eb18.js" as="script"><link rel="prefetch" href="/docs/assets/404.html-f9875e7b.js" as="script"><link rel="prefetch" href="/docs/assets/index.html-f24f1c0d.js" as="script"><link rel="prefetch" href="/docs/assets/code-gen.html-9aef4a31.js" as="script"><link rel="prefetch" href="/docs/assets/home.html-287156bf.js" as="script"><link rel="prefetch" href="/docs/assets/ioc-aop.html-c387c913.js" as="script"><link rel="prefetch" href="/docs/assets/scheduled-tasks.html-b338f70f.js" as="script"><link rel="prefetch" href="/docs/assets/user-info.html-8f482e6a.js" as="script"><link rel="prefetch" href="/docs/assets/home.html-7cba3ecd.js" as="script"><link rel="prefetch" href="/docs/assets/dbs.html-4250b788.js" as="script"><link rel="prefetch" href="/docs/assets/efcore.html-c2834bdb.js" as="script"><link rel="prefetch" href="/docs/assets/sql.html-e0d45a22.js" as="script"><link rel="prefetch" href="/docs/assets/simple.html-80586b86.js" as="script"><link rel="prefetch" href="/docs/assets/split.html-7a328015.js" as="script"><link rel="prefetch" href="/docs/assets/client.html-0c7bcd45.js" as="script"><link rel="prefetch" href="/docs/assets/download.html-27f039c3.js" as="script"><link rel="prefetch" href="/docs/assets/problem.html-9ef68938.js" as="script"><link rel="prefetch" href="/docs/assets/api.html-8c3a828a.js" as="script"><link rel="prefetch" href="/docs/assets/authorize.html-be0e89f8.js" as="script"><link rel="prefetch" href="/docs/assets/data.html-0f889ade.js" as="script"><link rel="prefetch" href="/docs/assets/api-check-model.html-8aaab178.js" as="script"><link rel="prefetch" href="/docs/assets/api-resource-cache.html-465cb7e9.js" as="script"><link rel="prefetch" href="/docs/assets/api-result.html-f2682747.js" as="script"><link rel="prefetch" href="/docs/assets/request-limit.html-c85ce0aa.js" as="script"><link rel="prefetch" href="/docs/assets/404.html-ee2a0c1c.js" as="script">
|
||
</head>
|
||
<body>
|
||
<div id="app"><!--[--><div class="theme-container"><!--[--><header class="navbar"><div class="toggle-sidebar-button" title="toggle sidebar" aria-expanded="false" role="button" tabindex="0"><div class="icon" aria-hidden="true"><span></span><span></span><span></span></div></div><span><a href="/docs/" class=""><!----><span class="site-name">您好, 欢迎查看 MiaoYu 文档 !</span></a></span><div class="navbar-items-wrapper" style=""><!--[--><!--]--><nav class="navbar-items can-hide"><!--[--><div class="navbar-item"><a class="external-link" href="https://www.bilibili.com/video/BV1tt4y157qH/" rel="noopener noreferrer" target="_blank" aria-label="视频讲解"><!--[--><!--]--> 视频讲解 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><div class="navbar-item"><a href="/docs/guide/others/home.md" class="" aria-label="其他项目"><!--[--><!--]--> 其他项目 <!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="http://124.221.128.7:5600/" rel="noopener noreferrer" target="_blank" aria-label="HzyAdmin 预览"><!--[--><!--]--> HzyAdmin 预览 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="https://gitee.com/hzy6" rel="noopener noreferrer" target="_blank" aria-label="gitee"><!--[--><!--]--> gitee <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="https://github.com/hzy-6" rel="noopener noreferrer" target="_blank" aria-label="github"><!--[--><!--]--> github <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><button class="toggle-color-mode-button" title="toggle color mode"><svg style="" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z" fill="currentColor"></path><path d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z" fill="currentColor"></path><path d="M2 15.005h5v2H2z" fill="currentColor"></path><path d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 25.005h2v5h-2z" fill="currentColor"></path><path d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z" fill="currentColor"></path><path d="M25 15.005h5v2h-5z" fill="currentColor"></path><path d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 2.005h2v5h-2z" fill="currentColor"></path></svg><svg style="display:none;" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z" fill="currentColor"></path></svg></button><!----></div></header><!--]--><div class="sidebar-mask"></div><!--[--><aside class="sidebar"><nav class="navbar-items"><!--[--><div class="navbar-item"><a class="external-link" href="https://www.bilibili.com/video/BV1tt4y157qH/" rel="noopener noreferrer" target="_blank" aria-label="视频讲解"><!--[--><!--]--> 视频讲解 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><div class="navbar-item"><a href="/docs/guide/others/home.md" class="" aria-label="其他项目"><!--[--><!--]--> 其他项目 <!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="http://124.221.128.7:5600/" rel="noopener noreferrer" target="_blank" aria-label="HzyAdmin 预览"><!--[--><!--]--> HzyAdmin 预览 <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="https://gitee.com/hzy6" rel="noopener noreferrer" target="_blank" aria-label="gitee"><!--[--><!--]--> gitee <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="https://github.com/hzy-6" rel="noopener noreferrer" target="_blank" aria-label="github"><!--[--><!--]--> github <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><ul class="sidebar-items"><!--[--><li><a href="/docs/guide/hzy-admin/home.md" class="sidebar-item sidebar-heading active collapsible" aria-label="HzyAdmin"><!--[--><!--]--> HzyAdmin <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a href="/docs/guide/hzy-admin/home.md" class="sidebar-item" aria-label="欢迎使用"><!--[--><!--]--> 欢迎使用 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/user-info.md" class="sidebar-item" aria-label="获取登陆人信息"><!--[--><!--]--> 获取登陆人信息 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/scheduled-tasks.md" class="sidebar-item" aria-label="定时任务"><!--[--><!--]--> 定时任务 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/code-gen.md" class="sidebar-item" aria-label="代码生成"><!--[--><!--]--> 代码生成 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/ioc-aop.md" class="sidebar-item" aria-label="自动 IOC 注入 和 AOP"><!--[--><!--]--> 自动 IOC 注入 和 AOP <!--[--><!--]--></a><!----></li><li><p tabindex="0" class="sidebar-item active collapsible">数据库 <span class="down arrow"></span></p><ul style="" class="sidebar-item-children"><!--[--><li><a href="/docs/guide/hzy-admin/database/efcore.md" class="sidebar-item" aria-label="EFCore 初始化数据库"><!--[--><!--]--> EFCore 初始化数据库 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/database/sql.md" class="sidebar-item" aria-label="SQL 初始化数据库"><!--[--><!--]--> SQL 初始化数据库 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/database/dbs.md" class="sidebar-item" aria-label="多数据源"><!--[--><!--]--> 多数据源 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/database/work.md" class="sidebar-item active" aria-label="事务,延迟提交"><!--[--><!--]--> 事务,延迟提交 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item collapsible">部署 <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/docs/guide/hzy-admin/deployment/split.md" class="sidebar-item" aria-label="前后端分离部署"><!--[--><!--]--> 前后端分离部署 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/deployment/simple.md" class="sidebar-item" aria-label="整体部署"><!--[--><!--]--> 整体部署 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item collapsible">权限 <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/docs/guide/hzy-admin/permission/authorize.md" class="sidebar-item" aria-label="授权验证"><!--[--><!--]--> 授权验证 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/permission/data.md" class="sidebar-item" aria-label="数据权限"><!--[--><!--]--> 数据权限 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/permission/api.md" class="sidebar-item" aria-label="接口权限"><!--[--><!--]--> 接口权限 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item collapsible">WebApi <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/docs/guide/hzy-admin/web-api/api-check-model.md" class="sidebar-item" aria-label="模型验证"><!--[--><!--]--> 模型验证 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/web-api/api-result.md" class="sidebar-item" aria-label="统一返回"><!--[--><!--]--> 统一返回 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/web-api/api-resource-cache.md" class="sidebar-item" aria-label="缓存特性"><!--[--><!--]--> 缓存特性 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/web-api/request-limit.md" class="sidebar-item" aria-label="限流特性"><!--[--><!--]--> 限流特性 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item collapsible">其他 <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/docs/guide/hzy-admin/others/client.md" class="sidebar-item" aria-label="前端运行及说明"><!--[--><!--]--> 前端运行及说明 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/others/download.md" class="sidebar-item" aria-label="前端下载文件"><!--[--><!--]--> 前端下载文件 <!--[--><!--]--></a><!----></li><li><a href="/docs/guide/hzy-admin/others/problem.md" class="sidebar-item" aria-label="更多问题"><!--[--><!--]--> 更多问题 <!--[--><!--]--></a><!----></li><!--]--></ul></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item sidebar-heading collapsible">其他项目 <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/docs/guide/others/home.md" class="sidebar-item" aria-label="介绍"><!--[--><!--]--> 介绍 <!--[--><!--]--></a><!----></li><!--]--></ul></li><!--]--></ul><!--[--><!--]--></aside><!--]--><!--[--><main class="page"><!--[--><!--]--><div class="theme-default-content"><!--[--><!--]--><div><h1 id="事务-延迟提交" tabindex="-1"><a class="header-anchor" href="#事务-延迟提交" aria-hidden="true">#</a> 事务,延迟提交</h1><h2 id="_1、事务特性" tabindex="-1"><a class="header-anchor" href="#_1、事务特性" aria-hidden="true">#</a> 1、事务特性</h2><div class="custom-container tip"><p class="custom-container-title">注意</p><p>1、函数必须是 virtual 事务特性才能起作用。</p><p>2、[Transactional] 特性默认读取 AdminDbContext 如何其他 DbContext 请指定 DbContextType。</p></div><div class="language-csharp line-numbers-mode" data-ext="cs"><pre class="language-csharp"><code><span class="token punctuation">[</span><span class="token attribute"><span class="token class-name">Transactional</span></span><span class="token punctuation">]</span>
|
||
<span class="token keyword">public</span> <span class="token keyword">virtual</span> <span class="token keyword">async</span> <span class="token return-type class-name">Task</span> <span class="token function">SaveFormAsync</span><span class="token punctuation">(</span><span class="token class-name">SysUserFormDto</span> form<span class="token punctuation">)</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token comment">// 你的业务逻辑 CRUD ...</span>
|
||
<span class="token punctuation">}</span>
|
||
|
||
<span class="token punctuation">[</span><span class="token attribute"><span class="token class-name">Transactional</span><span class="token attribute-arguments"><span class="token punctuation">(</span><span class="token keyword">typeof</span><span class="token punctuation">(</span><span class="token type-expression class-name">AdminDbContext</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token range operator">..</span><span class="token punctuation">.</span><span class="token punctuation">)</span></span></span><span class="token punctuation">]</span>
|
||
<span class="token keyword">public</span> <span class="token keyword">virtual</span> <span class="token keyword">async</span> <span class="token return-type class-name">Task</span> <span class="token function">SaveFormAsync</span><span class="token punctuation">(</span><span class="token class-name">SysUserFormDto</span> form<span class="token punctuation">)</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token comment">// 你的业务逻辑 CRUD ...</span>
|
||
<span class="token punctuation">}</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="_2、提交事务" tabindex="-1"><a class="header-anchor" href="#_2、提交事务" aria-hidden="true">#</a> 2、提交事务</h2><div class="language-csharp line-numbers-mode" data-ext="cs"><pre class="language-csharp"><code><span class="token keyword">public</span> <span class="token keyword">async</span> <span class="token return-type class-name">Task</span> <span class="token function">SaveFormAsync</span><span class="token punctuation">(</span><span class="token class-name">SysUserFormDto</span> form<span class="token punctuation">)</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token comment">// 创建事务对象</span>
|
||
<span class="token keyword">using</span> <span class="token class-name"><span class="token keyword">var</span></span> tr <span class="token operator">=</span> <span class="token keyword">await</span> _defaultRepository<span class="token punctuation">.</span>UnitOfWork<span class="token punctuation">.</span><span class="token function">BeginTransactionAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token keyword">try</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token comment">// 你的业务逻辑 CRUD ...</span>
|
||
<span class="token punctuation">}</span>
|
||
<span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span><span class="token punctuation">)</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token comment">// 回滚事务</span>
|
||
<span class="token keyword">await</span> tr<span class="token punctuation">.</span><span class="token function">RollbackAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token keyword">throw</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span>
|
||
<span class="token keyword">finally</span>
|
||
<span class="token punctuation">{</span>
|
||
<span class="token comment">// 提交事务</span>
|
||
<span class="token keyword">await</span> tr<span class="token punctuation">.</span><span class="token function">CommitAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
<span class="token punctuation">}</span>
|
||
<span class="token punctuation">}</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="_3、延迟提交" tabindex="-1"><a class="header-anchor" href="#_3、延迟提交" aria-hidden="true">#</a> 3、延迟提交</h2><div class="language-csharp line-numbers-mode" data-ext="cs"><pre class="language-csharp"><code><span class="token comment">// 开启延迟提交</span>
|
||
_defaultRepository<span class="token punctuation">.</span>UnitOfWork<span class="token punctuation">.</span><span class="token function">CommitDelayStart</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
|
||
<span class="token comment">// 你的业务逻辑 CRUD ...</span>
|
||
|
||
<span class="token comment">// 结束延迟提交</span>
|
||
_defaultRepository<span class="token punctuation">.</span>UnitOfWork<span class="token punctuation">.</span><span class="token function">CommitDelayEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></div><!--[--><!--]--></div><footer class="page-meta"><!----><div class="meta-item last-updated"><span class="meta-item-label">Last Updated: </span><!----></div><div class="meta-item contributors"><span class="meta-item-label">Contributors: </span><span class="meta-item-info"><!--[--><!--[--><span class="contributor" title="email: 1396510655@qq.com">hzy</span><!----><!--]--><!--]--></span></div></footer><!----><!--[--><!--]--></main><!--]--></div><!----><!--]--></div>
|
||
<script type="module" src="/docs/assets/app-4f4af2d5.js" defer></script>
|
||
</body>
|
||
</html>
|