【发布时间】:2015-10-11 10:57:19
【问题描述】:
我正在尝试在 MVC 6 中实现实体框架 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>();
}
}
}
【问题讨论】:
标签: c# asp.net entity-framework entity-framework-core asp.net-core-mvc