This project is currently in preview and not recommended for production use yet.
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"));
This preview has a number of limitations at this time. Please consider the following support matrix.
- 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
- Select projections
- Sum, Average, Min, Max etc.
- Value converters
- Type discriminators
- Logging
- Transactions
- Mapping configuration options
- Entity Framework Core 8
- GroupBy operations
- Properties with dictionary type
- Binary/byte array properties
- Keyless entity types
- Additional CLR types (DateOnly, TimeOnly etc).
- EF shadow properties
- Schema migrations
- Database-first & model-first
- Foreign keys and navigation traversal
- Joins
- Alternate keys
- Document (table) splitting
- Temporal tables
- Spacial data
- Timeseries
- Atlas search
If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here.
Please see our guidelines for contributing to the driver.
- Damien Guard [email protected]
- Oleksandr Poliakov [email protected]
- Robert Stam [email protected]