Code Samples
Initialize connection
await DB.InitAsync("bookshop","localhost");
Persist an entity
var book = new Book { Title = "The Power Of Now" };
await book.SaveAsync();
Embed as document
var dickens = new Author { Name = "Charles Dickens" };
book.Author = dickens.ToDocument();
await book.SaveAsync();
Update entity properties
await DB.Update<Book>()
.Match(b => b.Title == "The Power Of Now")
.Modify(b => b.Publisher, "New World Order")
.Modify(b => b.ISBN, "SOMEISBNNUMBER")
.ExecuteAsync();
One-To-One relationship
var hemmingway = new Author { Name = "Ernest Hemmingway" };
await hemmingway.SaveAsync();
book.MainAuthor = hemmingway;
await book.SaveAsync();
One-To-Many relationship
var tolle = new Author { Name = "Eckhart Tolle" };
await tolle.SaveAsync();
await book.Authors.AddAsync(tolle);
Many-To-Many relationship
var genre = new Genre { Name = "Self Help" };
await genre.SaveAsync();
await book.AllGenres.AddAsync(genre);
await genre.AllBooks.AddAsync(book);
Queries
var author = await DB.Find<Author>().OneAsync("ID");
var authors = await DB.Find<Author>().ManyAsync(a => a.Publisher == "Harper Collins");
var eckhart = await DB.Queryable<Author>()
.Where(a => a.Name.Contains("Eckhart"))
.SingleOrDefaultAsync();
var powerofnow = await genre.AllBooks
.ChildrenQueryable()
.Where(b => b.Title.Contains("Power"))
.SingleOrDefaultAsync();
var selfhelp = await book.AllGenres
.ChildrenQueryable()
.FirstAsync();
Delete
await book.MainAuthor.DeleteAsync();
await book.AllAuthors.DeleteAllAsync();
await book.DeleteAsync();
await DB.DeleteAsync<Genre>("ID");
await DB.DeleteAsync<Book>(b => b.Title == "The Power Of Now");
Tutorials
More Examples