T H
T H

Reputation: 395

Is it possible to use Entity Framework Core 6 with MongoDb?

Is it possible to use EF Core 6 in combination with a MongoDb? From what I'v gathered online, I could only find answers from a few years ago that say that it's still not possible, but nothing that was published recently. There is also better support for the Azure Cosmos Db which is also a NoSql database, so maybe I could use that to communicate with a MongoDb?

If it's still not possible, what other approach should I use?

Upvotes: 18

Views: 21039

Answers (4)

sommmen
sommmen

Reputation: 7618

There is no official MongoDb provider implementation for EF core at this time, I did not see any mention of MongoDb in the .net core 7 (the next version) roadmap as of now.

See: https://learn.microsoft.com/en-us/ef/core/providers/?tabs=dotnet-core-cli

I quickly googled a bit but could not find a recent version of a MongoDb provider.

Msdn docs also do not use EF core: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-6.0&tabs=visual-studio

Related SO: MongoDB and Entity Framework Core 2.0

UPDATE

From the 'supported providers' table, MongoDb is now supported!

NuGet Package Supported database engines Maintainer / Vendor Notes / Requirements For EF Core Useful links
MongoDB.EntityFrameworkCore MongoDB MongoDB Currently in preview 7 docs

See the quickstart!

Upvotes: 10

vlee
vlee

Reputation: 470

MongoDB has now released an officially supported EF Core provider (currently in preview).

Github repo: https://github.com/mongodb/mongo-efcore-provider

NuGet: https://www.nuget.org/packages/MongoDB.EntityFrameworkCore

Issue/bug tracker: https://jira.mongodb.org/projects/EF/issues/EF-63

Upvotes: 9

davey_lad
davey_lad

Reputation: 51

As of October 2023 an offical MongoDB Provider for EF Core is now in Public Preview.

https://www.mongodb.com/blog/post/mongodb-provider-entity-framework-core-now-available-public-preview

https://github.com/mongodb/mongo-efcore-provider

A production worthy version might still be some way off though.

Upvotes: 1

AptitudeDude
AptitudeDude

Reputation: 126

While there is no MongoDb provider for EF (to my disappointment), there is, at least, a provider for CosmosDb, Azure's fully managed NoSQL solution.

https://azure.microsoft.com/en-us/services/cosmos-db/

https://learn.microsoft.com/en-us/ef/core/providers/cosmos/?tabs=dotnet-core-cli

Once can't help but wonder if it's intentional -- but I imagine the unit-of-work pattern with transaction rollback as well as Migrations support.

In the mean time, you can consider something along the lines of the repository pattern so that your data access does not depend on your infrastructure.

I'd recommend taking a look at some of the samples and training by Ardalis (Steve Smith).

https://deviq.com/design-patterns/repository-pattern

Upvotes: 2

Related Questions