UseSqlServer 方法缺少 MVC 6 [英] UseSqlServer method missing MVC 6

查看:16
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆