简体   繁体   English

是否可以将 Entity Framework Core 6 与 MongoDb 一起使用?

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

Is it possible to use EF Core 6 in combination with a MongoDb?是否可以将 EF Core 6 与 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?对 Azure Cosmos Db 也有更好的支持,它也是一个 NoSql 数据库,所以也许我可以用它与 MongoDb 通信?

If it's still not possible, what other approach should I use?如果仍然不可能,我应该使用什么其他方法?

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.虽然 EF 没有 MongoDb 提供程序(令我失望),但至少有一个 CosmosDb 提供程序,Azure 的完全托管 NoSQL 解决方案。

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

https://learn.microsoft.com/en-us/ef/core/providers/cosmos/?tabs=do.net-core-cli https://learn.microsoft.com/en-us/ef/core/providers/cosmos/?tabs=do.net-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. Once 忍不住想知道这是否是故意的——但我想像具有事务回滚和迁移支持的工作单元模式。

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).我建议您看一下Ardalis (Steve Smith) 的一些示例和培训。

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

There is an open issue on MongoDB's site about providing an officially supported EF Core provider. MongoDB 站点上有一个关于提供官方支持的 EF Core 提供程序的未解决问题。 If this is something important to you, you can vote for it there.如果这对您很重要,您可以在那里投票 (note, you must sign up for an account on their site to vote) (注意,您必须在他们的网站上注册一个帐户才能投票)

https://jira.mongodb.org/browse/CSHARP-3837 https://jira.mongodb.org/browse/CSHARP-3837

Update:更新:
3/31/2022 - Status was changed to Backlog 3/31/2022 - 状态更改为积压
4/28/2022 - Status was changed to Needs Scope , Quarter set to FY23Q2 4/28/2022 - 状态更改为需要 Scope ,季度设置为FY23Q2
6/22/2022 - Status was changed to Scoping 6/22/2022 - 状态更改为范围界定
7/29/2022 - Quarter set to FY23Q3 2022 年 7 月 29 日 - 季度设置为FY23Q3
1/20/2023 - Status was chagned to Backlog 1/20/2023 - 状态更改为积压

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. EF 核心目前没有官方的 MongoDb 提供程序实现,我没有看到 .net 核心 7(下一个版本)路线图中提到 MongoDb。

See: https://docs.microsoft.com/en-us/ef/core/providers/?tabs=dotnet-core-cli请参阅: https://docs.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.我快速搜索了一下,但找不到 MongoDb 提供程序的最新版本。

Msdn docs also do not use EF core: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-6.0&tabs=visual-studio Msdn 文档也不使用 EF 核心: https://docs.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相关 SO: MongoDB 和 Entity Framework Core 2.0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以将 Entity Framework Core 与没有主键的表上的现有数据库一起使用? - Is it possible to use Entity Framework Core with existing database on tables with no primary key? 是否可以将 Sqlite 的 json 功能与 Entity Framework Core 一起使用 - Is it possible to use json features of Sqlite with Entity Framework Core 是否可以通过 Entity Framework Core 中的连接列进行排序? - Is it possible to order by a joined column in Entity Framework Core? 是否可以在Entity Framework Core中创建映射类? - Is it possible to create a mapping class in Entity Framework Core? 是否可以配置 Entity Framework Core >= 7.0 以使用 List<t> 而不是哈希集<t>通过配置?</t></t> - Is it possible to configure Entity Framework Core >= 7.0 to use List<T> instead of HashSet<T> by configuration? 是否可以在 Win Forms 应用程序中使用 Entity Framework Core? / 未找到参考文献警告 - Is it possible to use Entity Framework Core in a Win Forms Application? / References Not Found Warnings 如何将LinqPad与Entity Framework Core一起使用? - How to use LinqPad with Entity Framework Core? 如何在 Entity Framework Core 中使用 ValueGeneratedOnUpdateSometimes - How to use ValueGeneratedOnUpdateSometimes in Entity Framework Core 如何在实体框架和 EF Core 中使用 .Include() - How to use .Include() in Entity Framework and EF Core 在实体框架核心中使用“附加”作为Upsert - Use “Attach” as an Upsert in Entity Framework Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM