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" />
                    
Directory.Packages.props
<PackageReference Include="Silmoon.Data.LiteDB" />
                    
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.LiteDB --version 3.4.0-alpha.0
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=Silmoon.Data.LiteDB&version=3.4.0-alpha.0&prerelease
                    
Install as a Cake Tool

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>() 显式创建,并检查返回结果。

项目源码 · NuGet 包

Product 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.

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 55 11/12/2026
3.3.0 146 9/25/2026
3.2.1 178 6/22/2026
3.2.0 147 3/1/2026
1.8.0 248 3/2/2025
1.7.2 233 2/1/2025
1.7.1 199 1/7/2025
1.7.0 199 12/28/2024
0.0.1 251 8/19/2024