简体   繁体   English

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

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

Entity Framework Core does not support spatial data, which I need to use in my app. Entity Framework Core 不支持我需要在我的应用程序中使用的空间数据。

Can I use Entity Framework 6 in .net core?我可以在 .net core 中使用 Entity Framework 6 吗? If so, how can I register DatabaseContext in Startup.cs ?如果是这样,我如何在Startup.cs注册DatabaseContext

Update更新

You can now use EF 6.3 with .NET Core 3.0:您现在可以将 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 https://devblogs.microsoft.com/dotnet/annoucing-ef-core-3-0-and-ef-6-3-general-availability/#what-s-new-in-ef-6-3

Below is an excerpt.下面是摘录。 However, EF Core has come a long way these days and it's worth giving it another go before going back to something that's reaching end-of-life soon.但是,现在 EF Core 已经取得了长足的进步,值得再试一次,然后再回到即将结束生命的东西。 Specifically for your issue, EF Core supports mapping to spatial data types using the NetTopologySuite spatial library since version 2.2.专门针对您的问题, EF Core 支持使用NetTopologySuite 空间库从 2.2 版开始映射到空间数据类型

What's new in EF 6.3 EF 6.3 中的新增功能

  • Support for .NET Core 3.0支持 .NET Core 3.0

  • The EntityFramework package now targets .NET Standard 2.1 in addition to .NET Framework 4.x.除了 .NET Framework 4.x 之外,EntityFramework 包现在还面向 .NET Standard 2.1。

  • This means that EF 6.3 is cross-platform and supported on other operating systems besides Windows, like Linux and macOS.这意味着 EF 6.3 是跨平台的,并且支持除 Windows 之外的其他操作系统,如 Linux 和 macOS。

  • The migrations commands have been rewritten to execute out of process and work with SDK-style projects.迁移命令已被重写以在进程外执行并与 SDK 样式的项目一起使用。

  • Support for SQL Server HierarchyId.支持 SQL Server HierarchyId。

  • Improved compatibility with Roslyn and NuGet PackageReference.改进了与 Roslyn 和 NuGet PackageReference 的兼容性。

  • Added ef6.exe utility for enabling, adding, scripting, and applying migrations from assemblies.添加了 ef6.exe 实用程序,用于启用、添加、编写脚本和应用程序集迁移。 This replaces migrate.exe.这将替换 migrate.exe。 There are certain limitations when using EF 6.3 in .NET Core.在 .NET Core 中使用 EF 6.3 时存在某些限制。 For example:例如:

  • Data providers need to be also ported to .NET Core.数据提供程序也需要移植到 .NET Core。 We only ported the SQL Server provider, which is included in the EF 6.3 package.我们只移植了 SQL Server 提供程序,它包含在 EF 6.3 包中。

  • Spatial support won't be enabled with SQL Server because the spatial types aren't enabled to work with .NET Core. SQL Server 将不会启用空间支持,因为空间类型无法与 .NET Core 一起使用。

  • Note that this limitation applies to EF 6.3 but not to EF Core 3.0.请注意,此限制适用于 EF 6.3,但不适用于 EF Core 3.0。 The latter continues to support spatial using the NetTopologySuite library.后者使用 NetTopologySuite 库继续支持空间。

  • There's currently no support for using the EF designer directly on .NET Core or .NET Standard projects.目前不支持直接在 .NET Core 或 .NET Standard 项目上使用 EF 设计器。

Original Answer原答案

It isn't ready yet, but starting with .NET Core 3.0, you will be able to.它还没有准备好,但从 .NET Core 3.0 开始,您将能够做到。

https://blogs.msdn.microsoft.com/dotnet/2018/05/07/net-core-3-and-support-for-windows-desktop-applications/ 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.同样,EF6 将更新为在 .NET Core 3.0 上工作,为使用 EF6 的现有应用程序提供简单的前进路径。

https://youtu.be/GN54OV5cCBM?t=1146 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,我们已经宣布将移植到 .NET Core 上工作......

No, you can not directly, because EF6 doesn't support .NET Core.不,你不能直接,因为 EF6 不支持 .NET Core。 But, you can create another project, that compiles against full .NET framework and use it as a reference.但是,您可以创建另一个项目,该项目针对完整的 .NET 框架进行编译并将其用作参考。

MS has actually made a decent tutorial for this: https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6#reference-full-framework-and-ef6-in-the-asp-net-core-project MS 实际上为此做了一个不错的教程: https : //docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6#reference-full-framework-and-ef6-in-the- asp-net-core-project

Like @Niko said, you cannot directly with EF6 but there is a fork that allows it.就像@Niko说,你不能直接与EF6但有一个叉,允许它。

Disclaimer : I'm the owner of the project Entity Framework Classic免责声明:我是Entity Framework Classic项目的所有者

Entity Framework Classic is an EF6 fork. Entity Framework Classic 是一个 EF6 分支。 It's everything you like about EF6, but with better performance, must-have features, .NET Core support, and more.这是您喜欢 EF6 的一切,但具有更好的性能、必备功能、.NET Core 支持等。

There is a FREE Community version that includes pretty much everything and an Enterprise version that include additional features.有一个包含几乎所有内容的免费社区版和一个包含附加功能的企业版。

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

相关问题 不能将Asp.net核心2.0与实体框架6一起使用 - Can't use Asp.net core 2.0 with entity framework 6 反正在.NET Core中使用Entity Framework吗? - Is there anyway to use Entity Framework in .NET Core? 实体框架核心.NET CLI - Entity Framework Core .NET CLI 如何使用Asp.Net.Identity和Entity Framework 6在Asp.Net Core 2.0 Target Framework 4.6.1中设置身份? - How can I setup identity in Asp.Net Core 2.0 Target Framework 4.6.1 using Asp.Net.Identity and Entity Framework 6? 了解.NET Core和Entity Framework的版本 - Understanding versions of .NET Core and Entity Framework 如何使用.net-core和Entity Framework Core和Identity从thenInclude中获取特定列? - How do i get specific columns from a thenInclude using .net-core and Entity Framework Core and Identity? (asp.net core mvc)如何在UI层中使用identityUser与实体层中的产品 - (asp.net core mvc) How can I use identityUser in UI layer with product in entity layer 在 Entity Framework Core 和 ASP.NET Core 中加载相关数据 - Loading related data in Entity Framework Core and ASP.NET Core 如何将MongoDB驱动程序与C#ASP.NET核心API框架一起使用? - How can I use the MongoDB Driver with C# ASP.NET Core API framework? 在不使用.NET Core,.NET Core和.NET Framework互操作性的情况下使用Aurelia - Use Aurelia without .NET Core, NET Core - NET Framework interoperability
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM