gpt4 book ai didi

asp.net-core - EF7 测试版 4 : AddEntityFramework dont accept argument (Configuration)

转载 作者:行者123 更新时间:2023-12-01 14:59:49 25 4
gpt4 key购买 nike

我正在看这个例子: http://stephenwalther.com/archive/2015/01/17/asp-net-5-and-angularjs-part-4-using-entity-framework-7

我正在努力处理这段代码:

using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Data.Entity;
using creaservo.com.Models;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.AspNet.Hosting;

namespace creaservo.com
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
Configuration = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
}

public IConfiguration Configuration { get; set; }


public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();

// Register Entity Framework
services.AddEntityFramework(Configuration)
.AddSqlServer()
.AddDbContext<MoviesAppContext>();
}

public void Configure(IApplicationBuilder app)
{
app.UseMvc();
}
}
}

问题在于

        // Register Entity Framework
services.AddEntityFramework(Configuration)
.AddSqlServer()
.AddDbContext<MoviesAppContext>();

我在哪里遇到构建错误:

Error   CS1501  No overload for method 'AddEntityFramework' takes 1 arguments   

我在很多其他示例中看到了配置参数的相同用法。

不知道,怎么了....

最佳答案

看起来您正在学习的教程使用的是旧版本的 EF7 框架。 EntityFramework 7 beta 4 不再接受 AddEntityFramework 的任何参数。看起来 beta 5 也在同一条轨道上。

我相信你要找的是这个:

// Register Entity Framework
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MoviesAppContext>(options =>
{
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString"));
});

这简化了配置文件中所需的结构,因为 MoviesAppContext 只需要连接字符串,而不需要 EntityFrameworkData元素。

关于asp.net-core - EF7 测试版 4 : AddEntityFramework dont accept argument (Configuration),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30438236/

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