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.
Set up#
To use LiteDb with on-disk persistent storage:
-
Install the
Microsoft.AspNetCore.Datasync.LiteDbpackage from NuGet. -
Add a singleton for the
LiteDatabaseto 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
BsonMapperattributes 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"); } }
Support and further information#
For more information, review the LiteDb documentation.