UseSqlServer 方法缺少 MVC 6

编程入门 行业动态 更新时间:2024-10-20 20:37:09
本文介绍了UseSqlServer 方法缺少 MVC 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在 MVC 6 中实现实体框架 7,并在此页面上 这里 它说要做

I am trying to implement Entity Framework 7 in MVC 6, and on this page here it says to do

services.AddEntityFramework() .AddSqlServer() .AddDbContext<MusicStoreContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

但对我来说,UseSqlServer 方法不可见?有谁知道如何让它可见?或者这是配置实体框架的旧方法?

But for me, the UseSqlServer method isn't visible? Anyone know how to make it visible? Or is this an old way of configuring entity framework?

我的 startup.cs 文件看起来像这样

My startup.cs file looks like this

using FluentValidation; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; namespace me.namespace.project { public class Startup { public static IConfiguration Configuration { get; set; } public Startup(IHostingEnvironment env) { // Setup configuration sources. Configuration = new Configuration() .AddJsonFile("config.json") .AddEnvironmentVariables(); } public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // entity framework services.AddEntityFramework() .AddSqlServer() .AddDbContext<DataContext>(); } } }

推荐答案

UseSqlServer 是命名空间 Microsoft.Data.Entity 中的扩展方法,因此您需要导入它在您的代码中,如下所示:

UseSqlServer is an extension method in the namespace Microsoft.Data.Entity so you need to import that in your code, like this:

using Microsoft.EntityFrameworkCore;

更多推荐

UseSqlServer 方法缺少 MVC 6

本文发布于:2023-11-08 13:52:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   UseSqlServer   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!