惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
博客园 - 司徒正美
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
L
LangChain Blog
T
The Blog of Author Tim Ferriss
博客园 - 【当耐特】
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
雷峰网
雷峰网
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ

博客园 - wzwyc

搜索并下载WINDOWS系统补丁 VS2019/2022/2026内网安装闪退的问题 Windows 7开发环境的问题笔记 C#颜色转换 C#把整型数值转16进制字符串 RocketMQ调研笔记 20260507随笔 在Zed中设置Xiaomi MiMo OxyPlot显示Legend图例 apache-iotdb-0.13.3-all-bin在WINDOWS 11系统上部署运行的问题 任务栏上的图标无法正常显示 应用启动时加载XML报错的问题处理 Prism的LoadedCommand命令没有被调用的问题 C#编译报错:可在所有平台上访问此调用站点。"xxxxxxxxxx" 仅在 "Windows" 7.0 及更高版本 上受支持。 C#系统下LINUX系统下组播数据的接收 消除只能在WINDOWS系统上使用的编译报警提示 WpfMultiStyle笔记 Kafka调研笔记 利用HtmlAgilityPack抓取网页的标题 关于Process的使用 Anaconda使用笔记 python下的plotly把图表转换成HTML 利用NAudio实现对音频设备的控制(静音、音量调节) 利用MathNet.Numerics求均方根 .NET 8以上版本,字节数组转字符串 .NET 8项目下载所有依赖到指定目录 异常的处理
FreeSql事务型提交
wzwyc · 2026-09-02 · via 博客园 - wzwyc

安装

Install-Package FreeSql.Repository

示例代码

static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
    .UseConnectionString(FreeSql.DataType.MySql, connectionString)
    //Automatically synchronize the entity structure to the database.
    .UseAutoSyncStructure(true) 
    //Be sure to define as singleton mode
    .Build(); 

using (var uow = fsql.CreateUnitOfWork())
{
  var songRepo = fsql.GetRepository<Song>();
  var userRepo = fsql.GetRepository<User>();
  songRepo.UnitOfWork = uow; //Manually bind unit of work
  userRepo.UnitOfWork = uow;

  songRepo.Insert(new Song());
  userRepo.Update(...);

  uow.Orm.Insert(new Song()).ExecuteAffrows();
  //Note: uow.Orm and fsql are both IFreeSql
  //uow.Orm CRUD and uow are the same transaction (understood as temporary IFreeSql)
  //fsql CRUD and uow are not in the same transaction

  uow.Commit();
}

具体可参考:
https://github.com/dotnetcore/FreeSql/wiki/Unit-of-Work