我正在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相关问答推荐

缓存httpmessage内容

.net 中的 [] 括号是什么?

如何在现有数据库中创建 ASP.Net Identity 表?

httpCompression 和 urlCompression 有什么区别?

SignalR 不在服务器上使用 Session

在 DataTextField 中组合两个字段.这可能吗?

正在检索组件的 COM 类工厂......错误:80070005 访问被拒绝. (来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))

如何通过后面的代码不显示

Windows 运行 ASP.NET 的 IIS 替代方案

如何在新实现的接口或基类之间做出决定?

跟踪点有什么用途?

将 Http 请求读入字节数组

ASP.NET Core 中的 NuGet 包位置在哪里?

.NET - c# - 需要跨分区查询,但在 DocumentDB 数据访问上禁用了问题

InvalidOperationException:无法为角色创建 DbSet,因为此类型未包含在上下文模型中

在 JavaScript 中获取当前会话值?

如何在 ASP.NET 中通过 LAN 访问您的网站

主机与 DnsSafeHost

如何在 ASP.NET 响应中传递大文件?

如何检索 X509Store 中的所有证书