LiteDb
LiteDB
LiteDB is a serverless database delivered in a single small DLL written in .NET C# managed code. It’s a simple and fast NoSQL database solution for stand-alone applications. To use LiteDb with on-disk persistent storage:
Install the
Microsoft.AspNetCore.Datasync.LiteDb
package from NuGet.Add a singleton for the
LiteDatabase
to theProgram.cs
:const connectionString = builder.Configuration.GetValue<string>("LiteDb:ConnectionString"); builder.Services.AddSingleton<LiteDatabase>(new LiteDatabase(connectionString));
Derive models from the
LiteDbTableData
:public class TodoItem : LiteDbTableData { public string Title { get; set; } public bool Completed { get; set; } }
You can use any of the
BsonMapper
attributes that are supplied with the LiteDb NuGet package.Create a controller using the
LiteDbRepository
:[Route("tables/[controller]")] public class TodoItemController : TableController<TodoItem> { public TodoItemController(LiteDatabase db) : base() { Repository = new LiteDbRepository<TodoItem>(db, "todoitems"); } }