Skip to content
A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
C#
Branch: master
Clone or download
Latest commit 309a3a5 Sep 14, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Benchmark data migration support Jun 27, 2019
Examples data migration support Jun 27, 2019
MongoDB.Entities v8.1 release Sep 14, 2019
Tests v8.1 release Sep 14, 2019
.gitignore initial commit Apr 17, 2019
LICENSE Initial commit Apr 17, 2019
MongoDB.Entities.sln parallel thread benchmark project added May 1, 2019
README.md fix wiki link Sep 13, 2019
icon.png icon added Apr 25, 2019
icon.svg icon added Apr 25, 2019
mongod.cfg mongod.cfg update Jul 15, 2019
social.png refactored db class Apr 29, 2019

README.md

nuget Build status

MongoDB.Entities

This library simplifies access to mongodb by abstracting away the C# mongodb driver and providing some additional features on top of it. The API is clean and intuitive resulting in less lines of code that is more readable/ human friendly than driver code.

Advantages:

  • Never have to deal with ObjectIds or BsonDocuments.
  • Everything is type safe. No magic strings needed.
  • Built-in support for One-To-One, One-To-Many and Many-To-Many relationships.
  • Query data using LINQ, lambda expressions, filters and fluent aggregations.
  • Sorting, paging and projecting is made convenient.
  • Simple data migration framework similar to EntityFramework.
  • Programatically define indexes.
  • Full text search with text indexes.
  • Multi-document transaction support.
  • Easy bulk operations.
  • Update with aggregation pipeline stages.
  • Start a GeoNear aggregation pipeline.
  • Multiple database support.
  • Project types supported: .Net Standard 2 | .Net Core | ASP.Net Core

Documentation

the easy to use API is described in the wiki pages.

Code Sample

    //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 author = DB.Find<Author>().One("ID");

        var authors = DB.Find<Author>().Many(a => a.Publisher == "Harper Collins");

        var eckhart = DB.Queryable<Author>()
                        .Where(a => a.Name.Contains("Eckhart"))
                        .SingleOrDefault();

        var powerofnow = genre.AllBooks.ChildrenQueryable()
                                       .Where(b => b.Title.Contains("Power"))
                                       .SingleOrDefault();

        var genre = book.AllGenres.ChildrenQueryable().First();

    //Delete
        book.Delete();
        book.Authors.DeleteAll();
        DB.Delete<Genre>(genre.ID);

Code Examples

.net core console project: click here

integration/unit test project: click here

asp.net core web-api project: click here

solutions to stackoverflow questions: click here

Donations

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:

You can’t perform that action at this time.