Coder Social home page Coder Social logo

maximys / mongodb.entities Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dj-nitehawk/mongodb.entities

0.0 2.0 0.0 4.67 MB

A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management

License: MIT License

C# 100.00%

mongodb.entities's Introduction

nuget nuget tests license

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, BsonDocuments & magic strings.
  • Built-in support for One-To-One, One-To-Many and Many-To-Many relationships.
  • Query data using LINQ, lambda expressions, filters and aggregation pipelines.
  • Sorting, paging and projecting is made convenient.
  • Simple data migration framework similar to EntityFramework.
  • Programatically define indexes.
  • Full text search (including fuzzy matching) with text indexes.
  • Multi-document transaction support.
  • Easy bulk operations.
  • Update with aggregation pipeline stages & array filters.
  • Easy GeoSpatial search.
  • Stream files in chunks to and from mongodb (GridFS alternative).
  • Multiple database support.
  • Project types supported: .Net Standard 2.0 (.Net Core 2.0 & .Net Framework 4.6.1 or higher)

Documentation

Code Sample

    //Initialize database connection
        new DB("bookshop","localhost");

    //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.Author = dickens.ToDocument();
        book.Save();
    
    //One-To-One relationship
        var hemmingway = new Author { Name = "Ernest Hemmingway" };
        hemmingway.Save();
        book.MainAuthor = hemmingway;
        book.Save();

    //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();
        book.AllGenres.Add(genre);
        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 selfhelp = book.AllGenres.ChildrenQueryable().First();

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

Code Examples

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:

mongodb.entities's People

Contributors

dj-nitehawk avatar maximys avatar paolobriones avatar

Watchers

 avatar  avatar

mongodb.entities's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.