问题描述
我想知道是否可以轻松地在.NET Standard 2.0项目中设置EntityFrameworkCore。我一直在关注,但是需要.NET Core或Framework。
I was wondering if I could set-up my EntityFrameworkCore in a .NET Standard 2.0 project easily. I was following this Tutorial but it requires either .NET Core or Framework.
当我执行此步骤时:
Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
我收到此错误:
我想知道是否可以设置我的.NET Standard中的实体或是否应该执行最佳实践?
I am wondering if I could set-up my entity in .NET Standard or if there a best practice that I should be doing instead?
推荐答案
该错误消息表示:没有这样的消息作为可执行 .NET标准项目。它没有运行时,因为它只是用于多个不同运行时的类型转发机制。
The error message means this: There is no such thing as an executable .NET Standard project. There is no runtime for it because it is simply a type-forwarding mechanism for multiple different runtimes.
在编程方面,它是。您无法执行此操作,因为没有实现可运行。
In programming terms, it is a bit like trying to instantiate an interface. You can't do it because there is no implementation to run.
解决方案是为应用程序选择一个可执行平台 。您可以从可执行文件中引用任意多个.NET Standard库(只要它们与您的运行时兼容),但是可执行文件本身不能在.NET Standard上运行。它必须针对.NET Framework或.NET Core这样的平台才能执行。
The solution is to pick an executable platform for your application to run on. You can reference as many .NET Standard libraries as you like from your executable (as long as they are compatible with your runtime), but the executable itself cannot be run on .NET Standard. It must target a platform such as .NET Framework or .NET Core in order to execute.
换句话说,为了使用命令来搭建数据库,您必须必须以运行时为目标。因此,您既可以在针对主要可执行项目的同时运行此命令,也可以在解决方案中添加新的可执行项目以在其上运行它。
In other words, in order to use a command to scaffold your database, you have to target a runtime. So you will either need to run this command while targeting your main executable project or add a new executable project to your solution to run it on.
您可以在运行此命令时执行此命令。在CLI上使用
选项--startup-project = [Path_to_your_main_Project]
You can do this running your command on the CLI with the option--startup-project=[Path_to_your_main_Project]
这篇关于尝试在.Net Standard项目中设置Entity Framework核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!