Silmoon.Data.SqlServer 3.4.0-alpha.0

Prefix Reserved
This is a prerelease version of Silmoon.Data.SqlServer.
dotnet add package Silmoon.Data.SqlServer --version 3.4.0-alpha.0
                    
NuGet\Install-Package Silmoon.Data.SqlServer -Version 3.4.0-alpha.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="Silmoon.Data.SqlServer" Version="3.4.0-alpha.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Silmoon.Data.SqlServer" Version="3.4.0-alpha.0" />
                    
Directory.Packages.props
<PackageReference Include="Silmoon.Data.SqlServer" />
                    
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 Silmoon.Data.SqlServer --version 3.4.0-alpha.0
                    
#r "nuget: Silmoon.Data.SqlServer, 3.4.0-alpha.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 Silmoon.Data.SqlServer@3.4.0-alpha.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=Silmoon.Data.SqlServer&version=3.4.0-alpha.0&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Silmoon.Data.SqlServer&version=3.4.0-alpha.0&prerelease
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1 is deprecated because it is no longer maintained.
1.7.0 197 12/28/2024