Silmoon.Data.PostgreSql
3.4.0-alpha.0
Prefix Reserved
dotnet add package Silmoon.Data.PostgreSql --version 3.4.0-alpha.0
NuGet\Install-Package Silmoon.Data.PostgreSql -Version 3.4.0-alpha.0
<PackageReference Include="Silmoon.Data.PostgreSql" Version="3.4.0-alpha.0" />
<PackageVersion Include="Silmoon.Data.PostgreSql" Version="3.4.0-alpha.0" />
<PackageReference Include="Silmoon.Data.PostgreSql" />
paket add Silmoon.Data.PostgreSql --version 3.4.0-alpha.0
#r "nuget: Silmoon.Data.PostgreSql, 3.4.0-alpha.0"
#:package Silmoon.Data.PostgreSql@3.4.0-alpha.0
#addin nuget:?package=Silmoon.Data.PostgreSql&version=3.4.0-alpha.0&prerelease
#tool nuget:?package=Silmoon.Data.PostgreSql&version=3.4.0-alpha.0&prerelease
Silmoon.Data.PostgreSql
PostgreSQL 数据访问封装,提供 PgSqlExecuter、表达式查询与局部更新、批量插入、模型表名映射、索引和事务支持。目标框架为 .NET 10。
当前版本为预览版。
dotnet add package Silmoon.Data.PostgreSql --prerelease
下面通过模型特性指定表名,并按主键更新价格。连接字符串由应用配置传入。
using System.Linq.Expressions;
using Silmoon.Data;
using Silmoon.Data.Attributes;
using Silmoon.Data.Models;
using Silmoon.Data.PostgreSql;
namespace Example.Models
{
[ModelToSqlDataTable("products")]
public class Product : SqlObject
{
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
}
public static class ProductExample
{
public static int SetPrice(string connectionString, int productId, decimal price)
{
using var executer = new PgSqlExecuter(connectionString, typeof(Product).Namespace);
Expression<WhereAction<Product>> where = x => x.id == productId;
Expression<SetAction<Product>> set = x => new Product { Price = price };
return executer.SetObjects(default, where, set).AffectedRows;
}
}
}
构造 Executer 时会扫描指定命名空间中带 ModelToSqlDataTable 的模型并创建缺失表。省略命名空间会扩大扫描范围。已有表的结构同步由特性或 CreateTable 参数显式控制,索引可通过 SqlIndex 标注。
- 表名依次使用显式非空名称、模型特性和类型默认名。
GetObject<T>/GetObjects<T>从Result取得记录,通过SqlQueryOptions设置排序、分页、排除字段和更新锁。SetObjects<T>只更新初始化器中明确赋值的属性,支持0、false和null,返回结果中的AffectedRows表示生效行数。- 空查询条件表示无筛选。更新和删除拒绝空条件,显式
x => true表示全表写入。 - 更新锁通过
SqlQueryOptions.LockOptions = SqlLockOptions.UpdateLock选择,并要求有效事务。
事务由 BeginTransaction() 开始,并通过 CommitTransaction(transaction) 或 RollbackTransaction(transaction) 结束。省略 CRUD 的事务参数时使用当前上下文事务,显式事务位于参数末尾。显式传入 null 事务会被拒绝。
显式事务查询使用 GetObject<T>(tableName, condition, options, transaction),默认查询选项可传 null。同一事务内的操作按顺序执行。
SQL 查询与表达式说明 · 事务说明 · 项目源码
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Dapper (>= 2.1.89)
- Npgsql (>= 10.0.3)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.3)
- Silmoon (>= 3.1.0)
- Silmoon.Data (>= 3.4.0-alpha.0)
- Silmoon.Extensions (>= 3.1.0)
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 |
|---|---|---|
| 3.4.0-alpha.0 | 54 | 11/12/2026 |
| 3.3.1 | 122 | 9/25/2026 |
| 3.3.0 | 137 | 8/15/2026 |
| 3.2.1 | 144 | 6/22/2026 |
| 3.2.0 | 134 | 3/1/2026 |
| 0.0.2 | 216 | 7/12/2025 |
| 0.0.1 | 221 | 3/2/2025 |
| 0.0.1-alipa | 199 | 2/2/2025 |