gpt4 book ai didi

c# - UseSqlServer 方法缺少 MVC 6

转载 作者:IT王子 更新时间:2023-10-29 04:11:41 25 4
gpt4 key购买 nike

我正在尝试在 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>();

}
}
}

最佳答案

安装 Microsoft.EntityFrameworkCore.SqlServer 1.0.1 包对我有用Microsoft.EntityFrameworkCore 版本为 1.1.0

关于c# - UseSqlServer 方法缺少 MVC 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33064164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com