Skip to content

Instantly share code, notes, and snippets.

@garymedina
Last active July 11, 2022 11:39
Show Gist options
  • Save garymedina/d0288d822de9a38a723a3436f0748473 to your computer and use it in GitHub Desktop.
Save garymedina/d0288d822de9a38a723a3436f0748473 to your computer and use it in GitHub Desktop.
LiteDB Crud operations and path for use in ASP.NET
//ASP.NET Database path
var path = Server.MapPath("~/App_Data/site.db");
using (var db = new LiteDatabase(path))
{
//Sets or Creates a Table in DB
var bottles = db.GetCollection<Bottle>("Bottles");
//Creates a new bottle object and saves in db
var bottle = new Bottle
{
Name = "Something",
Price = 600
};
bottles.Insert(bottle);
//Get all the bottles to list
List<Bottle> _list = bottles.FindAll().ToList();
//Get a bottle by Id and update it
Bottle _bottle = bottles.FindOne(b => b.Id == 4);
_bottle.Name = "Kettle One";
bottles.Update(_bottle);
//Delete by Id
bottles.Delete(b=>b.Id == 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment