Tuesday, April 30, 2019

MongoDB Entities v3.6 released with Many-To-Many relationship support

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.

Code Sample

```csharp //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(); 

```

Wiki/Getting Started

in order to get started using the library please see the wiki pages.

MongoDB Entities v3.6 released with Many-To-Many relationship support Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team