Silmoon.Data.LiteDB
3.4.0-alpha.0
Prefix Reserved
This is a prerelease version of Silmoon.Data.LiteDB.
dotnet add package Silmoon.Data.LiteDB --version 3.4.0-alpha.0
NuGet\Install-Package Silmoon.Data.LiteDB -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.LiteDB" 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.LiteDB" Version="3.4.0-alpha.0" />
<PackageReference Include="Silmoon.Data.LiteDB" />
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.LiteDB --version 3.4.0-alpha.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Silmoon.Data.LiteDB, 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.LiteDB@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.LiteDB&version=3.4.0-alpha.0&prerelease
#tool nuget:?package=Silmoon.Data.LiteDB&version=3.4.0-alpha.0&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Silmoon.Data.LiteDB
LiteDB 嵌入式数据库封装,提供 LiteDBService、表达式查询、局部更新、文档替换、集合名称映射和模型索引管理。
安装
当前版本为预览版。
dotnet add package Silmoon.Data.LiteDB --prerelease
本包面向 .NET 10。下面的控制台示例使用本地数据库文件 example.db。
查询与局部更新
using System;
using System.Linq.Expressions;
using Silmoon.Data;
using Silmoon.Data.Attributes;
using Silmoon.Data.LiteDB;
using Silmoon.Data.LiteDB.Models;
using var service = new LiteDBService("Filename=example.db");
var symbol = new Symbol { Name = "DEMO", Price = 12.5m, Enabled = true };
service.Add(symbol);
Expression<WhereAction<Symbol>> where = x => x._id == symbol._id;
Expression<SetAction<Symbol>> set = x => new Symbol { Price = 0m, Enabled = false };
var updated = service.Set(where, set);
var saved = service.Get(where);
Console.WriteLine($"{saved.Name}: {saved.Price}; updated: {updated}");
[ModelToMongoCollection("symbols")]
public sealed class Symbol : IdObject
{
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
public bool Enabled { get; set; }
}
WhereAction<T> 表达筛选条件,SetAction<T> 只更新初始化器中明确赋值的属性,支持 0、false 和 null。示例中的 Name 和 _id 保留原值。
- LiteDB 集合名称同样使用
ModelToMongoCollection特性,未指定时按类型名称解析。 Set更新一条匹配记录,Sets更新全部匹配记录;完整文档替换使用Replace/Replaces。Gets支持排序表达式、offset和count,Count/Exists可直接查询记录数量和存在性。- 空筛选条件表示无筛选,单条操作作用于一条记录,批量操作作用于全部记录。
- 模型索引通过
EnsureModelIndexes<T>()显式创建,并检查返回结果。
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- LiteDB (>= 5.0.21)
- 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.