我想实现实体框架7 MVC 6,而这个页面here它说做UseSqlServer方法缺少MVC 6
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>();
}
}
}
谢谢你,这是正是我需要的 – Gillardo
完美的作品......现在得到了另一个问题说“没有配置数据库提供者。在设置服务时,通过在DbContext类或AddDbContext方法中重写OnConfiguring来配置数据库提供程序。“不知道为什么,因为我的startup.cs文件说明了conectionstring? – Gillardo
声音很容易修复,但这是另一个问题:) – DavidG