我正试图在MVC 6中实现实体框架7,在这个页面上,它说要做
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>();
}
}
}
安装Microsoft.EntityFrameworkCore.SqlServer 1.0.1包适用于我微软版本。EntityFrameworkCore是1.1.0
UseSqlServer
是名称空间Microsoft.Data.Entity
中的扩展方法,因此您需要在代码中导入它,如下所示:
using Microsoft.EntityFrameworkCore;
自发布以来,程序集已被重命名。作为EntityFrameworkCore的一部分,你现在需要添加如下的using语句
using Microsoft.EntityFrameworkCore;
配置上下文的。usesqlserver扩展方法将变得可用
这是NuGet Packages Problem
安装以下包并使用相应的版本
1. Microsoft.EntityFrameworkCore(Latest Version)
2. Microsoft.EntityFrameworkCore.SqlServer(1.0.4 Version)