我正在try 在MVC6中实现实体框架7,在这一页上,它说要做here

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

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

我的startup.cs文件是这样的

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中的一个扩展方法,因此需要在代码中导入它,如下所示:

using Microsoft.EntityFrameworkCore;

Asp.net相关问答推荐

在Docker Windows中,ASP.NET核心容器在自定义端口8080上运行,但ASP.NET容器在固定端口80上运行

如何在 C# 代码中获取当前项目名称?

ASP.NET @Register 与 @Reference

ASP.NET:获取自 1970 年 1 月 1 日以来的毫秒数

如何使用 SmtpClient.SendAsync 发送带有附件的邮箱?

Anti-Forgery Token 适用于不同的基于声明的用户

在 cookie 中存储多个值

在上下文中找不到 owin.Environment 项

学习什么 - Ruby on Rails 或 ASP .NET MVC...鉴于熟悉 ASP .NET

从 JavaScript 读取 web.config

HttpContext.Current.Cache.Insert 和 HttpContext.Current.Cache.Add 有什么区别

asp.net 有控制台日志(log)吗?

ASP.NET MVC 2.0 JsonRequestBehavior 全局设置

带有模型的 ASP.NET MVC 重定向

脚本管理器控制实际上是做什么的?

ASP.NET Excel 导出编码问题

错误处理(向客户端发送 ex.Message)

Ashx 文件中的 HttpContext.Current.Session 为空

以编程方式滚动到锚标记

ConfigurationManager.AppSettings 缓存