generateSql 1.0.7

dotnet add package generateSql --version 1.0.7
                    
NuGet\Install-Package generateSql -Version 1.0.7
                    
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="generateSql" Version="1.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="generateSql" Version="1.0.7" />
                    
Directory.Packages.props
<PackageReference Include="generateSql" />
                    
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 generateSql --version 1.0.7
                    
#r "nuget: generateSql, 1.0.7"
                    
#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 generateSql@1.0.7
                    
#: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=generateSql&version=1.0.7
                    
Install as a Cake Addin
#tool nuget:?package=generateSql&version=1.0.7
                    
Install as a Cake Tool

外部使用的辅助

  • 数据库类型 DatabaseType
MySQL MySQL
SqlServer SqlServer
  • TableColumn 生成建表语句时使用
类型 说明
Primarykey bool 是否为主键
ColumnName string 列字段
ColumnType Type 类型
Length int 长度
IsNull bool 是否为空
Description string 列描述
  • 枚举排序 SortOrder
NONE
ASC 升序
DESC 降序
  • 自定义属性 MyIsStructureAttribute
    • 在类上使用
      • 在生成SQL中,不使用时默认为类名
    • 在类的属性中使用
      • 在生成SQL中,不使用时默认都为表结构中的数据
参数 默认值
TableName (生成的表名) --
IsStructure (是否为表结构中的数据) false
  • 枚举类型 SqlType
Insert 增加
Delete 删除
Update 更新
Select 查询
TruncateTable 截断
  • 辅助方法
方法 参数 说明
ConvertToSqlType DatabaseType Type 转换为数据库类型

  • 主键使用 [Key] 标识
方法 参数 说明
GenerateTableMySql tableName (表名) tableColumns (字段列表) mysql 建表
GenerateTableSqlServer tableName (表名) tableColumns (字段列表) sqlserver 建表
CreatedTableSqlV1 DatabaseType tableName (表名) tableColumns (字段列表) 合并
CreatedTableMysqlSQL<T> 生成 mysql 创建语句
CreatedTableSQLServer<T> 生成 sqlServer 创建语句
CreatedTableSqlV2<T> DatabaseType 建表
GetTableAll DatabaseType db (mysql 需要,数据库名称) 获取表
GetTableDetail DatabaseType tablename(表名) db (mysql 需要,数据库名称) 获取表详情

生成SQL时的占位符

属性 默认值
ParamPrefix @

增删改查

基础

  • 新增
方法 说明
GenerateInsertSql 新增
参数 类型 说明
表名 string
参数 Dictionary<string, object> 键值的格式
  • 删除
方法 说明
GenerateDeleteSql 删除
参数 类型 说明
表名 string
无条件时为截断 string "" 条件 (1=1and2=2)
  • 修改
方法 说明
GenerateUpdateSql 修改
参数 类型 说明
表名 string
参数 Dictionary<string, object> 键值的格式
条件 string "" 条件 (1=1and2=2)
  • 查询
方法 说明
GenerateSelectSql 查询
参数 类型 说明
表名 string
查询的列 List<string> null
条件 string "" 条件 (1=1and2=2)
排序字段 string "" (id,time)
排序方式 SortOrder SortOrder.NONE
当前页 int 0
条数 int 0

使用泛型

  • 新增
方法
Add<T> 新增
参数 类型 说明
param List<string> null 新增字段
  • 截断
方法
TruncateTable<T> 截断
  • 删除
方法
Delete<T> 删除
参数 类型 说明
whereClause string "" 删除条件 (1=1and2=2)
  • 修改
方法
Update<T> 修改
参数 类型 说明
param List<string> null 更新字段
condition string "" 修改条件 (1=1and2=2)
  • 查询
方法
Query<T> 查询
参数 类型 说明
param List<string> null 查询指定字段
condition string "" 修改条件 (1=1and2=2)
orderByColumn string "" 排序字段 (id,time)
orderByClause SortOrder 排序类型(SortOrder.NONE)
v1 int 0 当前页
v2 int 0 条数

合并

方法
GetSqlV1 获取sql
参数 类型 说明
sqlType SqlType 类型
tableName string 表名
param Dictionary<string, object> 新增 / 修改 / 查询 字段
condition string "" 修改条件 (1=1and2=2)
orderByColumn string "" 排序字段 (id,time)
orderByClause SortOrder 排序类型(SortOrder.NONE)
v1 int 0 当前页
v2 int 0 条数
方法
GetSqlV2<T> 获取sql
参数 类型 说明
sqlType SqlType 类型
param List<string> 新增 / 修改 / 查询 字段
condition string "" 修改条件 (1=1and2=2)
orderByColumn string "" 排序字段 (id,time)
orderByClause SortOrder 排序类型(SortOrder.NONE)
v1 int 0 当前页
v2 int 0 条数
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 was computed.  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 was computed.  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 was computed.  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. 
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6

    • No dependencies.
  • net6.0

    • No dependencies.

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
1.0.7 262 3/7/2025
1.0.6 269 3/4/2025