The goal of this library is to simplify access to mongodb by wrapping up the official C# mongodb driver and providing some additional features on top of it. You get all the power of the official driver and then some. The API is clean and intuitive resulting in less lines of code that is more readable/ human friendly than driver code.
You never have to deal with ObjectIds
or BsonDocuments
. Everything will be type safe. You can get the best of both worlds by modelling your entities in either Document/NoSQL stye or Relational/SQL style or a mix of both.
There is built-in automatic support for One-To-One
, One-To-Many
and Many-To-Many
relationships.
Data can be queried using either LINQ or lambda expressions.
Supports both ASP.Net Core
and .Net Core
applications.
//Initialize database connection
new DB("bookshop");
//Create and persist an entity
var book = new Book { Title = "The Power Of Now" };
book.Save();
//Embed as document
var dickens = new Author { Name = "Charles Dickens" };
book.RelatedAuthor = dickens.ToDocument();
dickens.Save();
//One-To-One relationship
var hemmingway = new Author { Name = "Ernest Hemmingway" };
hemmingway.Save();
book.MainAuthor = hemmingway.ToReference();
//One-To-Many relationship
var tolle = new Author { Name = "Eckhart Tolle" };
tolle.Save();
book.Authors.Add(tolle);
//Many-To-Many relationship
var genre = new Genre { Name = "Self Help" };
genre.Save();
genre.AllBooks.Add(book);
//Queries
var eckhart = DB.Collection<Author>()
.Where(a => a.Name.Contains("Eckhart"))
.SingleOrDefault();
var powerofnow = genre.AllBooks.Collection()
.Where(b => b.Title.Contains("Power"))
.SingleOrDefault();
var selfhelp = book.AllGenres.Collection().First();
//Delete
genre.Delete();
book.Delete();
tolle.Delete();
in order to get started using the library please see the wiki pages.
.net core console project: click here
e2e/unit test project: click here
asp.net core web-api project: click here
if this library has made your life easier and you'd like to express your gratitude, you can donate a couple of bucks via paypal by clicking the button below: