UseSqlServer 方法缺少 MVC 6
UseSqlServer method missing MVC 6
我正在尝试在 MVC 6 中实现 Entity Framework 7,并且在此页面上 here 它说要做
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
但对我来说,UseSqlServer
方法不可见?任何人都知道如何让它可见?或者这是配置 entity framework 的旧方法?
我的 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;
自发布以来,程序集已重命名。作为 EntityFrameworkCore 的一部分,您现在需要添加以下 using 语句
using Microsoft.EntityFrameworkCore;
用于配置上下文的 .UseSqlServer 扩展方法将可用
安装 Microsoft.EntityFrameworkCore.SqlServer 1.0.1 包适合我
Microsoft.EntityFrameworkCore 的版本是 1.1.0
这是一个NuGet Packages Problem
安装以下软件包及其正确的版本
1. Microsoft.EntityFrameworkCore(Latest Version)
2. Microsoft.EntityFrameworkCore.SqlServer(1.0.4 Version)
我正在尝试在 MVC 6 中实现 Entity Framework 7,并且在此页面上 here 它说要做
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
但对我来说,UseSqlServer
方法不可见?任何人都知道如何让它可见?或者这是配置 entity framework 的旧方法?
我的 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;
自发布以来,程序集已重命名。作为 EntityFrameworkCore 的一部分,您现在需要添加以下 using 语句
using Microsoft.EntityFrameworkCore;
用于配置上下文的 .UseSqlServer 扩展方法将可用
安装 Microsoft.EntityFrameworkCore.SqlServer 1.0.1 包适合我 Microsoft.EntityFrameworkCore 的版本是 1.1.0
这是一个NuGet Packages Problem
安装以下软件包及其正确的版本
1. Microsoft.EntityFrameworkCore(Latest Version)
2. Microsoft.EntityFrameworkCore.SqlServer(1.0.4 Version)