1.LiteDB 一个小巧、快速、轻量级的 NoSQL 嵌入式数据库
2。100% C# 代码,支持 .NET 3.5 / .NET 4.0 / NETStandard 1.3 / NETStandard 2.0,单 DLL (小于 300 kb)
支持sql语句
# get the first 5 documents from the movies collection
Find-LiteDBDocument movies -Sql "Select $ from movies limit 5"
# get the first 5 documents with selected properties or fields from the movies collection
Find-LiteDBDocument movies -Sql "Select _id,Title from movies limit 5"
# using where to filter the results - string filter
Find-LiteDBDocument movies -Sql "Select _id,Title from movies Where MPAA = 'PG-13'"
# using where to filter the results - greaterthan
Find-LiteDBDocument movies -Sql "Select _id,Title from movies Where Rating > 7.5"
# using multiple where filters. ( movies that contain 'talking' in their title)
Find-LiteDBDocument movies -Sql "Select _id,Title from movies where MPAA = 'PG-13' and Title like '%talking'"
# Sorting by name descending
Find-LiteDBDocument movies -Sql "Select _id,Title from movies where MPAA = 'PG-13' order by Title desc"
# date filter
Find-LiteDBDocument movies -Sql "select _id,Title,ReleaseDate from test where ReleaseDate > datetime('8/16/1989') order by Releasedate desc"
# using Functions
# get the first 5 documents with selected properties or fields from the movies collection
Find-LiteDBDocument movies -Sql "Select upper(Title),_id,MPAA from movies limit 5"
C# 使用
// 创建你的 POCO 类
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string[] Phones { get; set; }
public bool IsActive { get; set; }
}
// 打开数据库 (如果不存在则创建)
using(var db = new LiteDatabase(@"MyData.db"))
{
// 获得 customer 集合
var col = db.GetCollection<Customer>("customers");
// 创建你的新 customer 实例
var customer = new Customer
{
Name = "John Doe",
Phones = new string[] { "8000-0000", "9000-0000" },
Age = 39,
IsActive = true
};
// 在 Name 字段上创建唯一索引
col.EnsureIndex(x => x.Name, true);
// 插入新的 customer 文档 (Id 是自增的)
col.Insert(customer);
// 更新集合中的一个文档
customer.Name = "Joana Doe";
col.Update(customer);
// 使用 LINQ 查询文档 (未使用索引)
var results = col.Find(x => x.Age > 20);
}
using(var db = new LiteDatabase(@"MyData.db"))
{
var gsi = gs.Query<ISSGateSentryInfo>().FirstOrDefault();
gsi.DutyID = result.Data.DUTYID;
gsi.DutyName = result.Data.USER_NAME;
gsi.DutyCode = result.Data.USER_CODE;
gsi.DutyTime = DateTime.Now;
gs.Update<ISSGateSentryInfo>(gsi);
});