SmartDapper 1.0.0
There is a newer version of this package available.
See the version list below for details.
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" />
<PackageReference Include="SmartDapper" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=SmartDapper&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 + UnitOfWorkSmartDapper.Middleware:ASP.NET Core 中间件 + 声明式事务([UnitOfWork])
| Product | Versions 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.
-
net8.0
- Dapper (>= 2.1.66)
- Microsoft.Extensions.Logging (>= 9.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Logging.Console (>= 9.0.10)
- Microsoft.Extensions.ObjectPool (>= 9.0.10)
- System.ComponentModel.Annotations (>= 5.0.0)
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.