[英]How to use EF6 (DB-first) with ASP.NET core web application(.NET framework 4.6.1)?
I am building asp.net core web application using full .NET framework 4.6.1 template like this-我正在使用完整的 .NET 框架 4.6.1 模板构建 asp.net 核心 web 应用程序 -
My project.json shows-我的项目.json 显示-
"frameworks": {
"net461": { }
},
I wanted to use EF6 (not EF core) , hence install entity framework using NuGet package manager using this command-我想使用EF6 (not EF core) ,因此使用 NuGet package manager 安装实体框架 -
Install-Package Entityframework
Project.json added this entry- Project.json 添加了此条目-
"EntityFramework": "6.1.3",
When I am trying to create a DBcontext and model using below Command:当我尝试使用以下命令创建 DBcontext 和 model 时:
Scaffold-DbContext "Server=XXXXX;Database=XXXXXXX;User Id=XXXXXXX;password=XXXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t TABLENAME
It throws below error:它抛出以下错误:
Scaffold-DbContext: The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Scaffold-DbContext:术语“Scaffold-DbContext”未被识别为 cmdlet、function、脚本文件或可运行程序的名称。
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
As I understand (since I have Powershell v3.0 and .NET core 1.0.1), rest of the EF tools and dependencies are missing in my project.json. As I understand (since I have Powershell v3.0 and .NET core 1.0.1), rest of the EF tools and dependencies are missing in my project.json. So which are tools and dependencies I need to add in my project.json to use EF6 (not EF core)?那么我需要在我的项目中添加哪些工具和依赖项。json 才能使用 EF6(不是 EF 核心)?
Some of the options I can see are like below.我可以看到的一些选项如下所示。 But not sure which one is right for EF6但不确定哪个适合 EF6
"EntityFramework.MicrosoftSqlServer": “EntityFramework.MicrosoftSqlServer”:
"EntityFramework.SqlServer": “EntityFramework.SqlServer”:
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final" “Microsoft.EntityFrameworkCore.SqlServer”:“1.0.0-rc2-final”
I didn't get what you mean by using core in .net but if you are targeting you project to old .net you need to install compatible version.我没有明白你在 .net 中使用核心的意思,但如果你的目标是项目到旧的 .net,你需要安装兼容版本。
For .net 4.8 following package version will work:对于 .net 4.8 以下 package 版本将起作用:
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 3.1.25
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.