栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

实体框架6事务回滚

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

实体框架6事务回滚

您不需要

Rollback
手动调用,因为您正在使用该
using
语句。

DbContextTransaction.Dispose
方法将在
using
块的末尾被调用。如果未成功提交事务(未调用或遇到异常),它将自动回滚事务。以下是
SqlInternalTransaction.Dispose
方法的源代码(
DbContextTransaction.Dispose
使用SqlServer提供程序时将最终委托给该方法):

private void Dispose(bool disposing){    // ...    if (disposing && this._innerConnection != null)    {        this._disposing = true;        this.Rollback();    }}

您会看到,它检查是否

_innerConnection
不为null,如果不为null,则回滚事务(如果已提交,则为
_innerConnection
null)。让我们看看
Commit
它的作用:

internal void Commit() {    // Ignore many details here...    this._innerConnection.ExecuteTransaction(...);    if (!this.IsZombied && !this._innerConnection.IsYukonOrNewer)    {        // Zombie() method will set _innerConnection to null        this.Zombie();    }    else    {        this.ZombieParent();    }    // Ignore many details here...}internal void Zombie(){    this.ZombieParent();    SqlInternalConnection innerConnection = this._innerConnection;    // Set the _innerConnection to null    this._innerConnection = null;    if (innerConnection != null)    {        innerConnection.DisconnectTransaction(this);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/575934.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号