Silmoon.Data.SqlServer
3.4.0-alpha.0
Prefix Reserved
dotnet add package Silmoon.Data.SqlServer --version 3.4.0-alpha.0
NuGet\Install-Package Silmoon.Data.SqlServer -Version 3.4.0-alpha.0
<PackageReference Include="Silmoon.Data.SqlServer" Version="3.4.0-alpha.0" />
<PackageVersion Include="Silmoon.Data.SqlServer" Version="3.4.0-alpha.0" />
<PackageReference Include="Silmoon.Data.SqlServer" />
paket add Silmoon.Data.SqlServer --version 3.4.0-alpha.0
#r "nuget: Silmoon.Data.SqlServer, 3.4.0-alpha.0"
#:package Silmoon.Data.SqlServer@3.4.0-alpha.0
#addin nuget:?package=Silmoon.Data.SqlServer&version=3.4.0-alpha.0&prerelease
#tool nuget:?package=Silmoon.Data.SqlServer&version=3.4.0-alpha.0&prerelease
Silmoon.Data.SqlServer
SQL Server 数据访问封装,提供 SqlServerExecuter、表达式查询与局部更新、批量插入、模型表名映射、索引和事务支持。目标框架为 .NET Standard 2.0。
当前版本为预览版。
dotnet add package Silmoon.Data.SqlServer --prerelease
下面通过模型特性指定表名,并按主键更新价格。连接字符串由应用配置传入。
using System.Linq.Expressions;
using Silmoon.Data;
using Silmoon.Data.Attributes;
using Silmoon.Data.Models;
using Silmoon.Data.SqlServer;
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 SqlServerExecuter(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 | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Data.SqlClient (>= 7.1.1)
- Newtonsoft.Json (>= 13.0.4)
- 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 | 0 | 11/12/2026 | |
| 3.3.1 | 123 | 9/25/2026 | |
| 3.3.0 | 138 | 8/15/2026 | |
| 3.2.1 | 156 | 6/22/2026 | |
| 3.2.0 | 148 | 3/1/2026 | |
| 2.0.0 | 232 | 9/21/2025 | |
| 1.8.2 | 200 | 7/12/2025 | |
| 1.8.1 | 249 | 3/8/2025 | |
| 1.8.0 | 220 | 3/2/2025 | |
| 1.7.6 | 234 | 2/2/2025 | |
| 1.7.5 | 222 | 2/1/2025 | |
| 1.7.4 | 211 | 1/21/2025 | |
| 1.7.3 | 225 | 12/29/2024 | |
| 1.7.2 | 213 | 12/29/2024 | |
| 1.7.1 | 221 | 12/29/2024 | |
| 1.7.0 | 197 | 12/28/2024 |