简体   繁体   English

如何将 EF6(DB 优先)与 ASP.NET 核心 web 应用程序(.NET 框架 4.6.1)一起使用?

[英]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 应用程序 -

1

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.

相关问题 DB-First与ASP.NET Web API 2 + EF6的身份验证混淆 - DB-First authentication confusion with ASP.NET Web API 2 + EF6 WebApp Azure 发布:我的 db-first WebApp (ASP.NET 4.8) 上出现 EF6 Model 验证错误 - WebApp Azure Publish: I'm getting EF6 Model Validation Errors on my db-first WebApp (ASP.NET 4.8) 将EF6与ASP.NET Core一起使用 - Use EF6 with ASP.NET Core 要在 EF Core 中添加不带外键的导航属性,使用 .NET Core Web API 进行 DB 优先迁移 - To add navigation property without foreign key in EF Core, DB-first migration with .NET Core Web API ASP.Net核心Web应用程序(.Net Framework)发布EF Code First方法 - ASP.Net Core Web Application(.Net Framework) issues EF Code First approach ASP.NET核心EF6身份 - ASP.NET Core EF6 Identity EF6 Enable-Migrations在ASP.NET Core(.NET Framework)中不起作用 - EF6 Enable-Migrations not working in ASP.NET Core (.NET Framework) EF Code First迁移替代ASP.NET Core应用程序 - EF Code First migrations alternative for ASP.NET Core application ASP.NET Web Api 2 / EF6首次调用的初始化性能 - ASP.NET Web Api 2 / EF6 first call initialization performance 如何在使用 EF 的 asp.net core 3.1 MVC 应用程序中正确使用我的 SQLite 数据库? - How do I properly use my SQLite db in my asp.net core 3.1 MVC application using EF?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM