SmartDapper 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SmartDapper --version 1.0.0
                    
NuGet\Install-Package SmartDapper -Version 1.0.0
                    
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="SmartDapper" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmartDapper" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SmartDapper" />
                    
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 SmartDapper --version 1.0.0
                    
#r "nuget: SmartDapper, 1.0.0"
                    
#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 SmartDapper@1.0.0
                    
#: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=SmartDapper&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SmartDapper&version=1.0.0
                    
Install as a Cake Tool

SmartDapper

SmartDapper 是一个基于 Dapper 的轻量级扩展库,提供 表达式树转 SQL通用 CRUD分页查询多数据库适配(SQL Server / MySQL / SQLite)。默认参数化执行,以降低 SQL 注入风险。

安装

dotnet add package SmartDapper

快速开始(SQL 生成 + Dapper 执行)

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Dapper;
using Microsoft.Data.SqlClient;
using SmartDapper.SqlGenerator;

[Table("Users")]
public class User
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public string UserName { get; set; } = string.Empty;
    public bool IsActive { get; set; }
}

var generator = SqlGeneratorFactory.CreateSqlServer<User>();
var (sql, parameters) = generator.GetSelectAll(u => u.IsActive);

using var conn = new SqlConnection("Server=.;Database=MyDb;Trusted_Connection=True;TrustServerCertificate=True;");
var users = conn.Query<User>(sql, parameters).ToList();

使用扩展方法(IDbConnection

using Microsoft.Data.SqlClient;
using SmartDapper.Extensions;

using var conn = new SqlConnection("Server=.;Database=MyDb;Trusted_Connection=True;TrustServerCertificate=True;");

var list = await conn.GetAllListAsync<User>(u => u.IsActive);
var (items, total) = await conn.GetPagedListAsync<User>(skip: 0, take: 20);

多数据库支持

  • SQL Server:SqlGeneratorFactory.CreateSqlServer<T>()
  • MySQL:SqlGeneratorFactory.CreateMySql<T>()
  • SQLite:SqlGeneratorFactory.CreateSqlite<T>()

相关包

  • SmartDapper.Repository:Repository + UnitOfWork
  • SmartDapper.Middleware:ASP.NET Core 中间件 + 声明式事务([UnitOfWork]
Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SmartDapper:

Package Downloads
SmartDapper.Repository

SmartDapper.Repository 提供通用的 Repository 抽象与 UnitOfWork 实现,封装常用 CRUD、分页和事务边界,帮助你用一致的方式组织数据访问层代码。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.1.0 56 2/3/2026
5.0.0 120 1/29/2026
4.0.0-beta001 50 1/22/2026
3.0.0 62 1/13/2026
2.3.0 123 1/4/2026
2.1.1 70 12/31/2025
2.1.0 57 12/30/2025
2.0.0 59 12/29/2025
1.1.1 113 12/26/2025
1.1.0 108 12/26/2025
1.0.0 151 12/25/2025