Giter Site home page Giter Site logo

mongodb / mongo-efcore-provider Goto Github PK

View Code? Open in Web Editor NEW
263.0 28.0 20.0 7.61 MB

MongoDB Entity Framework Core Provider

Home Page: https://www.nuget.org/packages/MongoDB.EntityFrameworkCore

License: Other

C# 99.08% Shell 0.71% CSS 0.21%
csharp entity-framework entity-framework-core mongodb

mongo-efcore-provider's Introduction

MongoDB Entity Framework Core Provider

The MongoDB EF Core Provider requires Entity Framework Core 8 on .NET 8 or later.

Getting Started

Setup a DbContext with your desired entities and configuration

internal class PlanetDbContext : DbContext
{
    public DbSet<Planet> Planets { get; init; }

    public static PlanetDbContext Create(IMongoDatabase database) =>
        new(new DbContextOptionsBuilder<PlanetDbContext>()
            .UseMongoDB(database.Client, database.DatabaseNamespace.DatabaseName)
            .Options);

    public PlanetDbContext(DbContextOptions options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<Planet>().ToCollection("planets");
    }
}

To get going with the DbContext:

var mongoConnectionString = Environment.GetEnvironmentVariable("MONGODB_URI");
var mongoClient = new MongoClient(mongoConnectionString);
var db = PlanetDbContext.Create(mongoClient.GetDatabase("planets"));

Supported Features

Entity Framework Core and MongoDB have a wide variety of features. This provider supports a subset of the functionality available in both, specifically:

  • Querying with Where, Find, First, Single, OrderBy, ThenBy, Skip, Take etc.
  • Top-level aggregates of Any, Count, LongCount
  • Mapping properties to BSON elements using [Column] or [BsonElement] attributes or HasElementName("name") method
  • Mapping entities to collections using [Table("name")] attribute or ToCollection("name") method
  • Single or composite keys of standard types including string, Guid and ObjectId
  • Properties with typical CLR types (int, string, Guid, decimal), Mongo types (ObjectId, Decimal128)
  • Properties containing arrays and lists of simple CLR types
  • Owned entities (aka value types, sub-documents, embedded documents) both directly and within collections
  • BsonIgnore, BsonId, BsonDateTimeOptions, BsonElement and BsonRequired support
  • Value converters using HasConversion
  • Query and update logging including MQL (sensitive mode only)
  • Some mapping configuration options for DateTime

Limitations

A number of Entity Framework Core features are not currently supported but planned for future release. If you require use of these facilities in the mean-time consider using the existing MongoDB C# Driver's LINQ provider which supports them.

They are:

  • Select projections must only contain server-translatable expressions
  • Sum, Average, Min, Max etc. are not supported at top level
  • Transactions
  • Type discriminators
  • Additional mapping configuration options

Not supported but considering for future releases

  • ExecuteUpdate & ExecuteDelete
  • Properties of Dictionary type
  • Binary/byte array properties
  • Additional CLR types (DateOnly, TimeOnly etc).
  • EF shadow properties
  • GroupBy operations
  • Relationships between entities
  • Includes/joins
  • Foreign keys and navigation traversal

Not supported & out-of-scope features

  • Keyless entity types
  • Schema migrations
  • Database-first & model-first
  • Alternate keys
  • Document (table) splitting
  • Temporal tables
  • Spacial data
  • Timeseries
  • Atlas search

Documentation

Questions/Bug Reports

If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here.

Contributing

Please see our guidelines for contributing to the driver.

Maintainers:

mongo-efcore-provider's People

Contributors

damieng avatar rstam avatar sanych-sun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.