我可以在 .net 核心中使用 Entity Framework 6(不是核心)吗?

Can I use Entity Framework 6 (not core) in .net core?

Entity Framework Core 不支持我需要在我的应用程序中使用的空间数据。

我可以在 .net 核心中使用 Entity Framework 6 吗?如果是这样,我如何在Startup.cs中注册DatabaseContext

UPDATE:是的,EF6 从 6.3 版开始就已经跨平台了。 https://devblogs.microsoft.com/dotnet/announcing-ef-core-3-0-and-ef-6-3-general-availability/#what-s-new-in-ef-6-3


现在无效的原始答案:不,您不能直接使用,因为 EF6 不支持 .NET Core。 但是,您可以创建另一个项目,针对完整的 .NET 框架进行编译并将其用作参考。

MS居然为此做了一个不错的教程: https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6#reference-full-framework-and-ef6-in-the-asp-net-core-project

更新

您现在可以将 EF 6.3 与 .NET Core 3.0 一起使用:

https://devblogs.microsoft.com/dotnet/announcing-ef-core-3-0-and-ef-6-3-general-availability/#what-s-new-in-ef-6-3

以下是节选。然而,EF Core 这些天已经取得了长足的进步,值得再试一次,然后再回到即将结束生命周期的东西。专门针对您的问题,EF Core supports mapping to spatial data types using the NetTopologySuite spatial library 自版本 2.2 以来。

What’s new in EF 6.3

  • Support for .NET Core 3.0

  • The EntityFramework package now targets .NET Standard 2.1 in addition to .NET Framework 4.x.

  • This means that EF 6.3 is cross-platform and supported on other operating systems besides Windows, like Linux and macOS.

  • The migrations commands have been rewritten to execute out of process and work with SDK-style projects.

  • Support for SQL Server HierarchyId.

  • Improved compatibility with Roslyn and NuGet PackageReference.

  • Added ef6.exe utility for enabling, adding, scripting, and applying migrations from assemblies. This replaces migrate.exe. There are certain limitations when using EF 6.3 in .NET Core. For example:

  • Data providers need to be also ported to .NET Core. We only ported the SQL Server provider, which is included in the EF 6.3 package.

  • Spatial support won’t be enabled with SQL Server because the spatial types aren’t enabled to work with .NET Core.

  • Note that this limitation applies to EF 6.3 but not to EF Core 3.0. The latter continues to support spatial using the NetTopologySuite library.

  • There’s currently no support for using the EF designer directly on .NET Core or .NET Standard projects.

原答案

它还没有准备好,但是从 .NET Core 3.0 开始,您将能够。

https://blogs.msdn.microsoft.com/dotnet/2018/05/07/net-core-3-and-support-for-windows-desktop-applications/

Similarly, EF6 will be updated to work on .NET Core 3.0, to provide a simple path forward for existing applications using EF6.

https://youtu.be/GN54OV5cCBM?t=1146

But there's also EF6, which we've already announced is going to be ported to work on .NET Core...

更新: 是的,EF6 从 6.3 版开始就是跨平台的。 https://devblogs.microsoft.com/dotnet/announcing-ef-core-3-0-and-ef-6-3-general-availability/#what-s-new-in-ef-6-3


现在无效的原始答案:就像@Niko 说的,你不能直接使用 EF6 但有一个分支允许它。

免责声明:我是项目的所有者Entity Framework Classic

Entity Framework Classic 是 EF6 分支。 EF6 拥有您喜欢的一切,但具有更好的性能、必备功能、.NET Core 支持等。

有一个包含几乎所有内容的免费社区版本和一个包含附加功能的企业版本。