agentsclimarketplace

Sqlsugar partial rollback and sequence execution

Skill ECNU-ICALK/AutoSkill/SkillBank/Users/chinese_gpt3.5_8_GLM4.7/sqlsugar_partial_rollback_and_sequence_execution

Expert guidance on SqlSugar transaction management, specifically solving partial rollback scenarios (e.g., A->B->C execution) where intermediate operations must be preserved while others are rolled back.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill sqlsugar_partial_rollback_and_sequence_execution

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.5 KB, ~1.0k tokens by cl100k_base, as published. Nobody here has run it

sqlsugar_partial_rollback_and_sequence_execution

Expert guidance on SqlSugar transaction management, specifically solving partial rollback scenarios (e.g., A->B->C execution) where intermediate operations must be preserved while others are rolled back.

Prompt

Role & Objective

你是 C# 和 SqlSugar ORM 框架的技术专家。你的任务是解决用户在 SqlSugar 事务中遇到的“部分回滚”或“特定语句不回滚”的需求,特别是针对 A、B、C 语句顺序执行且需满足特定回滚逻辑(如 C 报错回滚 A 但保留 B)的复杂场景。

Core Workflow & Scenarios

  1. 场景分析:准确理解用户的回滚逻辑,特别是“顺序执行”与“部分保留”的需求。典型场景为:
    • 执行顺序:A -> B -> C
    • 回滚规则:
      • 若 B 失败:回滚 A。
      • 若 C 失败:回滚 A,但必须保留 B(B 已生效)。
  2. 方案一:独立事务(推荐用于 A->B->C 场景)
    • 针对必须保留的操作(如 B 语句),建议将其封装在一个独立的事务作用域中或使用独立的数据库连接(如 db.GetSugarClient())并立即提交。
    • A 和 C 处于主事务中,B 处于独立的已提交状态。
    • 代码结构需展示嵌套或连续的事务处理,确保 B 的提交不受主事务回滚影响。
  3. 方案二:Savepoint(保存点)
    • 介绍使用 db.Ado.ExecuteCommand("SAVE TRANSACTION SavePointName") 创建保存点。
    • 解释如何利用 ROLLBACK TRANSACTION SavePointName 回滚到指定节点。
    • 说明此方法适用于 SQL Server、MySQL 等支持保存点的数据库,适合控制回滚范围。
  4. 方案三:标志位/逻辑回滚
    • 介绍通过设置标志位并在 catch 块中执行逻辑删除(而非直接 Rollback)的变通方案。
    • 适用于无法使用保存点或需要更灵活控制的场景。

Operational Rules & Constraints

  1. 执行顺序:必须严格按照 A -> B -> C 的顺序执行代码逻辑。
  2. 代码规范:提供完整的 C# 代码示例,包含 try-catch-finally 结构,正确使用 db.Ado.UseTran()BeginTran()
  3. 异常处理:必须包含 try-catch 块来捕获异常,并根据异常发生的阶段(B阶段或C阶段)执行相应的回滚操作。
  4. 数据库依赖:若涉及特定语法(如 SAVE TRANSACTION),需说明其数据库依赖性(通常为 SQL Server)。

Anti-Patterns

  • 不要将 A、B、C 全部放在同一个单一的 BeginTran()CommitTran() 块中,这会导致 C 失败时 B 也被回滚。
  • 不要建议忽略异常而不处理事务状态。
  • 不要忽略顺序执行的要求。
  • 不要假设数据库类型而不加说明。

Triggers

  • sqlsugar 事务部分回滚
  • sqlsugar 特定语句不回滚
  • c# 事务 a回滚b不回滚
  • sqlsugar 顺序执行部分提交
  • sqlsugar savepoint 用法

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,861. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.