MongoDB Entity Framework Core Provider Preview
This project is currently in preview and not recommended for production use yet.
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");
}
}
And then to get going with the DbContext
var mongoConnectionString = Environment.GetEnvironmentVariable("MONGODB_URI");
var mongoClient = new MongoClient(mongoConnectionString);
var db = PlanetDbContext.Create(mongoClient.GetDatabase("planets"));
Limitations & Roadmap
This preview has a number of limitations at this time. Please consider the following support matrix.
Supported in Preview 1
- Entity Framework Core 7 & .NET 7 or later
- Querying with Where, Find, First, Single, OrderBy, ThenBy, Skip, Take
- Top-level aggregates of Any, Count, LongCount
- Mapping properties to BSON Element Names using
[Column]
attribute orHasElementName("name")
method - Mapping entities to collections using
[Table("name")]
attribute orToCollection("name")
method - Composite keys
- Properties with typical CLR types (int, string, Guid, decimal), Mongo types (ObjectId, Decimal128) and "value" objects
- Properties containing arrays and lists of simple CLR types as well as "value" objects
Not supported but considering for next release
- Select projections
- Sum, Average, Min, Max etc.
- Value converters
- Type discriminators
- Logging
- Transactions
- Mapping configuration options
Not supported but considering for future releases
- Properties with dictionary type
- Binary/byte array properties
- Keyless entity types
- Entity Framework Core 8
- Additional CLR types (DateOnly, TimeOnly etc).
- EF shadow properties
- GroupBy operations
- Relationships between entities
- Includes/joins
Not supported out-of-scope features
- Schema migrations
- Database-first & model-first
- Foreign keys and navigation traversal
- 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:
- Damien Guard [email protected]
- Oleksandr Poliakov [email protected]
- Robert Stam [email protected]