Guest User

Untitled

a guest
Dec 13th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. //ASP.NET Database path
  2. var path = Server.MapPath("~/App_Data/site.db");
  3.  
  4.  
  5. using (var db = new LiteDatabase(path))
  6. {
  7. //Sets or Creates a Table in DB
  8. var bottles = db.GetCollection<Bottle>("Bottles");
  9.  
  10. //Creates a new bottle object and saves in db
  11. var bottle = new Bottle
  12. {
  13. Name = "Something",
  14. Price = 600
  15. };
  16. bottles.Insert(bottle);
  17.  
  18.  
  19. //Get all the bottles to list
  20. List<Bottle> _list = bottles.FindAll().ToList();
  21.  
  22. //Get a bottle by Id and update it
  23. Bottle _bottle = bottles.FindOne(b => b.Id == 4);
  24. _bottle.Name = "Kettle One";
  25. bottles.Update(_bottle);
  26.  
  27. //Delete by Id
  28. bottles.Delete(b=>b.Id == 4);
Add Comment
Please, Sign In to add comment