本文介绍了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
发布评论