版权属于:
一缕清风_一个分享心得的网站_程序员_个人博客
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
LiteDB 是一个 .NET 开发的小型快速轻量级的 NoSQL 嵌入式数据库
官网地址:http://www.litedb.org/
可视化工具:https://github.com/mbdavid/LiteDB.Studio
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UsbDemo
{
public class LiteDbDemo
{
public void Test()
{
using (var db = new LiteDB.LiteDatabase("MyData.db"))
{
//新增/创建集合
var col = db.GetCollection<LiteDbModel>("LiteDbModel");
//插入数据
var customer = new LiteDbModel { Id = 1, Name = "John Doe", Sex = "男" };
col.Insert(customer);
//更新数据
customer.Name = "Joana Doe1";
col.Update(customer);
//删除数据
col.DeleteMany(x=>x.Name== "Joana Doe1");
//根据id删除数据
col.Delete(1);
//删除全部
col.DeleteAll();
// 查询单条
var sing = col.FindOne(x => x.Name== "Joana Doe1");
//查询全部
var all = col.FindAll();
//lambda表达式查询
var lambda = col.Find(x=>x.Name.Contains("Joana"));
}
}
}
public class LiteDbModel
{
//Id字段必须
public int Id { get; set; }
public string Name { get; set; }
public string Sex { get; set; }
}
}
评论 (0)