Easy.WorkFlow.SqlSugar 2.3.11

There is a newer version of this package available.
See the version list below for details.
dotnet add package Easy.WorkFlow.SqlSugar --version 2.3.11
                    
NuGet\Install-Package Easy.WorkFlow.SqlSugar -Version 2.3.11
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Easy.WorkFlow.SqlSugar" Version="2.3.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Easy.WorkFlow.SqlSugar" Version="2.3.11" />
                    
Directory.Packages.props
<PackageReference Include="Easy.WorkFlow.SqlSugar" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Easy.WorkFlow.SqlSugar --version 2.3.11
                    
#r "nuget: Easy.WorkFlow.SqlSugar, 2.3.11"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Easy.WorkFlow.SqlSugar@2.3.11
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Easy.WorkFlow.SqlSugar&version=2.3.11
                    
Install as a Cake Addin
#tool nuget:?package=Easy.WorkFlow.SqlSugar&version=2.3.11
                    
Install as a Cake Tool

Easy.WorkFlow.SqlSugar

Easy.WorkFlow.SqlSugar 是基于 SqlSugar ORM 的 Easy.WorkFlow 工作流存储适配器,提供了完整的工作流数据持久化解决方案,支持多种数据库。本库支持 .NET 6、.NET 7、.NET 8 和 .NET 9。

功能特性

  • 完整的数据持久化:提供工作流定义、实例和步骤处理的完整存储支持
  • 多数据库支持:基于 SqlSugar ORM,支持 SQLServer、MySQL、PostgreSQL、Oracle、SQLite 等多种数据库
  • 自动实体映射:使用 Mapster 实现 SqlSugar 实体与工作流领域对象之间的自动映射
  • 代码优先迁移:支持自动创建数据库和表结构
  • 灵活配置:支持通过代码或配置文件配置数据库连接
  • SQL 处理器:内置 SqlRrocessor,支持工作流步骤中执行 SQL 操作
  • 分页查询支持:支持工作流相关数据的分页和动态查询
  • 关系映射:支持工作流与步骤、实例与处理记录等关联数据的自动加载

更新日志

  • 2.3.11
    • 升级:升级Easy.WorkFlow.Core到2.3.9版本,具体见 [Easy.WorkFlow.Core 更新日志]
  • 2.3.10
    • 升级:升级Easy.WorkFlow.Core到2.3.8版本,具体见 [Easy.WorkFlow.Core 更新日志]
  • 2.3.9
    • 升级:升级Easy.WorkFlow.Core到2.3.7版本,具体见 [Easy.WorkFlow.Core 更新日志]
    • 调整:解析ISqlSugarClient时添加验证判断。
  • 2.3.8
    • 修复:修复在个别情况下会出现MultipleActiveResultSets错误的问题;
  • 2.3.7
    • 升级Easy.WorkFlow.Core到2.3.6版本,具体见 [Easy.WorkFlow.Core 更新日志]
  • 2.3.6
    • 调整:根据指定数据库的连接id获取ISqlSugarClient。
  • 2.3.5
    • 升级Easy.WorkFlow.Core到2.3.5版本,具体见 [Easy.WorkFlow.Core 更新日志]
    • 新增:新增SqlSugarUnitOfWork工作单元,支持事务处理。
  • 2.3.4
    • 升级Easy.WorkFlow.Core到2.3.4版本,具体见 [Easy.WorkFlow.Core 更新日志]
  • 2.3.3
    • 升级Easy.WorkFlow.Core到2.3.3版本,具体见 [Easy.WorkFlow.Core 更新日志]
    • SqlSugar依赖升级到5.1.4.198版本
  • 2.3.1
    • 升级Easy.WorkFlow.Core到2.3.1版本,具体见 [Easy.WorkFlow.Core 更新日志]
  • 2.3.0
    • 升级Easy.WorkFlow.Core到2.3.0版本,具体见 [Easy.WorkFlow.Core 更新日志]
    • 修复:修复了ISqlSugarClient Scope注册方式不正确的问题,IsAutoCloseConnection未正确设置的问题。
    • 修复:修复了UpdateTWFAsync更新工作流未使用导航更新导致工作流步骤Steps未更新的问题。
  • 2.2.2
    • 升级Easy.WorkFlow.Core到2.2.2版本,具体见 [Easy.WorkFlow.Core 更新日志]
  • 2.2.1
    • 升级Easy.WorkFlow.Core到2.2.1版本,具体见 [Easy.WorkFlow.Core 更新日志]
    • 添加注释文档
  • 2.2.0
    • 升级Easy.WorkFlow.Core到2.2.0版本,具体见 [Easy.WorkFlow.Core 更新日志]
  • 2.1.0
    • 升级Easy.WorkFlow.Core到2.1.0版本,具体见 [Easy.WorkFlow.Core 更新日志]

快速开始

1. 安装包

dotnet add package Easy.WorkFlow.SqlSugar

2. 注册服务

Program.csStartup.cs 中注册 SqlSugar 工作流存储服务:

// 首先注册工作流核心服务
services.AddWorkFlow();

// 方式一:从默认配置节 "SqlSugar" 中读取数据库配置
services.AddWorkFlowSqlSugar(configuration);

// 方式二:自定义配置数据库连接
services.AddWorkFlowSqlSugar(configuration, options =>
{
    // 指定配置节名称,指定后将从配置文件对应的节点读取配置,下面的配置将不生效
    options.SectionName = "WorkFlowDb";
    
    // 或者直接配置连接信息
    options.DbType = DbType.SqlServer; // 数据库类型
    options.ConnectionString = "Server=.;Database=WorkFlow;Uid=sa;Pwd=123456;"; // 连接字符串
    options.IsAutoCloseConnection = true;
    
    // 数据库初始化设置
    options.DbSettings = new DbSettings
    {
        EnableInitDb = true, // 启用数据库初始化
        EnableUnderLine = true // 启用驼峰转下划线命名
    };
    
    // 表结构初始化设置
    options.TableSettings = new TableSettings
    {
        EnableInitTable = true // 启用表结构初始化
    };
});

3. 配置 appsettings.json

{
  "SqlSugar": {
    "DbType": "SqlServer",
    "ConnectionString": "Server=.;Database=WorkFlow;Uid=sa;Pwd=123456;",
    "IsAutoCloseConnection": true,
    "DbSettings": {
      "EnableInitDb": true,
      "EnableUnderLine": true
    },
    "TableSettings": {
      "EnableInitTable": true
    }
  }
}

数据模型

Easy.WorkFlow.SqlSugar 提供了以下核心数据模型:

  • Sugar_WF:工作流定义,包含工作流的基本信息和版本控制
  • Sugar_WFStep:工作流步骤,定义工作流中的各个节点和操作
  • Sugar_WFInstance:工作流实例,记录工作流的执行状态和数据
  • Sugar_WFProcess:工作流处理记录,记录每个步骤的处理状态和结果

仓储接口

ISqlSugarWorkFlowRepository

该接口提供直接访问 SqlSugar 实体的方法:

// 获取工作流定义
var workflow = await _sqlSugarWorkFlowRepository.GetSugar_WF(workflowId);

// 分页查询工作流实例,支持前端json构造
var pageInput = new WhereDynamicFilterPageInput
{
    Page = 1,
    PageSize = 10,
    Where = new List<ConditionalModel>
    {
        new ConditionalModel { FieldName = "Status", ConditionalType = ConditionalType.Equal, FieldValue = "1" }
    }
};
var instances = await _sqlSugarWorkFlowRepository.GetSugar_WFInstancePagedList(pageInput);

// 获取用户处理的工作流实例
var myInstances = await _sqlSugarWorkFlowRepository.GetSugar_MyHandlePagedList(userId, pageInput);

与 Easy.WorkFlow.Core 集成

Easy.WorkFlow.SqlSugar 通过 SqlSugarWorkFlowRepositoryWithAdapter 适配器实现了 Easy.WorkFlow.Core 的 IWorkFlowRepository 接口,提供了领域对象与数据库实体之间的无缝转换。

使用时无需直接调用适配器,Easy.WorkFlow.Core 中的 IWorkFlowService 会自动使用注册的 IWorkFlowRepository 实现。

SQL 处理器

SqlSugar 包提供了 SqlRrocessor 实现,用于执行工作流步骤中定义的 SQL 操作:

// 在工作流步骤中定义 SQL 处理器
var sqlStep = new DL_WFStep
{
    // 其他属性...
    ProcessorType = ProcessorType.SQL,
    Processor = "UPDATE Orders SET Status = 'Approved' WHERE Id = @OrderId",
    ProcessorContext = "OrderId=[data.orderId]"
};

处理器会自动从工作流表单数据中解析参数,并执行 SQL 操作。

高级用法

动态查询

使用 WhereDynamicFilterPageInput 进行动态条件查询(支持前端json构造):

var queryInput = new WhereDynamicFilterPageInput
{
    Page = 1,
    PageSize = 10,
    Where = new List<ConditionalModel>
    {
        new ConditionalModel 
        { 
            FieldName = "CreatedTime", 
            ConditionalType = ConditionalType.GreaterThan, 
            FieldValue = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") 
        },
        new ConditionalModel 
        { 
            FieldName = "Status", 
            ConditionalType = ConditionalType.Equal, 
            FieldValue = WFStatus.Running.ToString("d") 
        }
    },
    OrderByFields = "CreatedTime desc"
};

var result = await _sqlSugarWorkFlowRepository.GetSugar_WFInstancePagedList(queryInput);

工作流实例状态管理

Easy.WorkFlow.SqlSugar 提供了工作流实例状态枚举 WFStatus,用于表示工作流实例的不同状态:

/// <summary>
/// 工作流实例状态枚举
/// </summary>
public enum WFStatus
{
    /// <summary>
    /// 待运行
    /// </summary>
    Pending = 0,

    /// <summary>
    /// 运行中
    /// </summary>
    Running = 1,

    /// <summary>
    /// 已完成
    /// </summary>
    Completed = 2,

    /// <summary>
    /// 已终止
    /// </summary>
    Stopped = 3,

    /// <summary>
    /// 已挂起
    /// </summary>
    Suspend = 4,
}

可以通过 Sugar_WFInstance.Status 属性获取或设置工作流实例的状态。

注意事项

  • 首次使用时,确保开启 EnableInitDbEnableInitTable 选项,以自动创建数据库和表结构
  • 在生产环境中,建议关闭自动初始化功能,通过数据库迁移工具管理架构变更
  • SqlSugar 实体使用 Mapster 映射到 Easy.WorkFlow.Core 的领域对象,修改实体结构时需要注意映射关系
  • 工作流表单数据以 JSON 字符串形式存储在 Data 字段中,查询时可使用数据库的 JSON 查询功能
  • Easy.WorkFlow.SqlSugar 默认使用原生模式以Scope注入SqlSugar 实例,数据库初始化时不受你项目的配置影响,在使用ISqlSugarWorkFlowRepository进行数据库查询时受你项目配置影响即你可以注入自己的SqlSugar实例。

依赖项

  • Easy.WorkFlow.Core >= 2.3.0
  • SqlSugarCore >= 5.1.4
  • Mapster >= 7.4.0

许可证

Easy.WorkFlow.SqlSugar 使用 MIT 许可证。

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.3.20 108 9/4/2025
2.3.19 164 8/29/2025
2.3.18 208 8/7/2025
2.3.17 262 7/29/2025 2.3.17 is deprecated because it has critical bugs.
2.3.16 177 7/28/2025 2.3.16 is deprecated because it is no longer maintained.
2.3.15 174 7/28/2025 2.3.15 is deprecated because it has critical bugs.
2.3.13 174 7/28/2025 2.3.13 is deprecated because it has critical bugs.
2.3.12 172 7/28/2025 2.3.12 is deprecated because it has critical bugs.
2.3.11 524 7/24/2025 2.3.11 is deprecated because it has critical bugs.
2.3.10 864 7/24/2025 2.3.10 is deprecated because it is no longer maintained.
2.3.9 926 7/22/2025 2.3.9 is deprecated because it is no longer maintained.
2.3.8 953 7/22/2025 2.3.8 is deprecated because it is no longer maintained.
2.3.7 945 7/22/2025 2.3.7 is deprecated because it is no longer maintained.
2.3.6 943 7/22/2025 2.3.6 is deprecated because it is no longer maintained.
2.3.5 675 7/20/2025 2.3.5 is deprecated because it is no longer maintained.
2.3.4 608 7/15/2025 2.3.4 is deprecated because it is no longer maintained.
2.3.3 607 7/14/2025 2.3.3 is deprecated because it is no longer maintained.
2.3.1 573 7/11/2025 2.3.1 is deprecated because it is no longer maintained.
2.3.0 626 7/9/2025 2.3.0 is deprecated because it is no longer maintained.
2.2.2 611 6/30/2025 2.2.2 is deprecated because it is no longer maintained.
2.2.1 611 6/30/2025 2.2.1 is deprecated because it is no longer maintained.
2.2.0 567 6/28/2025 2.2.0 is deprecated because it is no longer maintained.
2.1.0 616 6/26/2025 2.1.0 is deprecated because it is no longer maintained.
2.0.0 613 6/25/2025 2.0.0 is deprecated because it is no longer maintained.