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

查看:324
本文介绍了UseSqlServer方法缺少MVC 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MVC 6中实现Entity Framework 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 isnt 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天全站免登陆