LiteDB NoSQL 嵌入式数据库 项目简介
LiteDB 是一个 .NET 开发的小型快速轻量级的 NoSQL 嵌入式数据库,特性:无服务器的 NoSQL 文档存储,数据存储在单一文件中类似 MongoDB 的简单 API100% C# 代码,支持 .NET 3.5,单一 DLL,可从 NuGet 安装: Install-Package LiteDB支持 ACID 事务控制日志模式下的写失败恢复可存储 POCO 类或者 BsonDocument支持文件存储和数据流存储 (like GridFS in MongoDB)单一数据文件存储,类似 SQLite文档字段索引,用于快速搜索支持使用 LINQ 查询Shell 命令行 (get on - try this online version开源使用方法:// Open data file (or create if not exits)
using(var db = new LiteEngine(@"C:\Temp\MyData.db"))
{
// Get a collection (or create, if not exits)
var col = db.GetCollection<Customer>("customers");
var customer = new Customer { Id = 1, Name = "John Doe" };
// Insert new customer document
col.Insert(customer);
// Update a document inside a collection
customer.Name = "Joana Doe";
col.Update(customer);
// Index document using a document property
col.EnsureIndex(x => x.Name);
// Simple Linq support
var result = col.Find(x => x.Name.StartsWith("Jo"));
}
using(var db = new LiteEngine(@"C:\Temp\MyData.db"))
{
// Get a collection (or create, if not exits)
var col = db.GetCollection<Customer>("customers");
var customer = new Customer { Id = 1, Name = "John Doe" };
// Insert new customer document
col.Insert(customer);
// Update a document inside a collection
customer.Name = "Joana Doe";
col.Update(customer);
// Index document using a document property
col.EnsureIndex(x => x.Name);
// Simple Linq support
var result = col.Find(x => x.Name.StartsWith("Jo"));
}