
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
MongoDB.EntityFrameworkCore
Advanced tools
Official MongoDB supported provider for Entity Framework Core 8. See https://www.mongodb.com/docs/entity-framework/ for more details.
The MongoDB EF Core Provider requires Entity Framework Core 8 or 9 on .NET 8 or later and a MongoDB database server 5.0 or later, preferably in a transaction-enabled configuration.
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"));
db.Database.EnsureCreated();
Entity Framework Core and MongoDB have a wide variety of features. This provider supports a subset of the functionality available in both, specifically:
Where
, Find
, First
, Single
, OrderBy
, ThenBy
, Skip
, Take
etc.Any
, Count
, LongCount
, Sum
, Min
, Max
, Average
, All
[Column]
or [BsonElement]
attributes or HasElementName("name")
method[Table("name")]
, ToCollection("name")
or by convention from the DbSet property nameGuid
and ObjectId
etc.int
, string
, Guid
, decimal
, DateOnly
etc.) & MongoDB types (ObjectId
, Decimal128
)byte[]
BsonIgnore
, BsonId
, BsonDateTimeOptions
, BsonElement
, BsonRepresentation
and BsonRequired
supportEnsureCreated
& EnsureDeleted
to ensure collections and the database created at app start-upIsConcurrencyToken
/ConcurrencyCheckAttribute
& IsRowVersion
/TimestampAttribute
SaveChanges
& SaveChangesAsync
- all changes committed or rolled-back togetherCamelCaseElementNameConvention
for helping map Pascal-cased C# properties to camel-cased BSON elementsOfType<T>
and Where(e => e is T)
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 may support them.
This project's version-numbers are aligned with Entity Framework Core and as-such we can not use the semver convention of constraining breaking changes solely to major version numbers. Please keep an eye on our Breaking Changes document before upgrading to a new version of this provider.
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.
Thank you to everyone who has contributed to this project.
FAQs
Official MongoDB supported provider for Entity Framework Core 8. See https://www.mongodb.com/docs/entity-framework/ for more details.
We found that mongodb.entityframeworkcore demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.