Last active
July 11, 2022 11:39
-
-
Save garymedina/d0288d822de9a38a723a3436f0748473 to your computer and use it in GitHub Desktop.
LiteDB Crud operations and path for use in ASP.NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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