用 dotnet run 运行 asp.net core 站点时,出现下面的错误:
/git/AboutUs/Startup.cs(62,22): error CS1061: 'IServiceCollection' does not contain a definition for 'AddEntityFramework' and no extension method 'AddEntityFramework' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
Starup.cs 中的对应代码如下:
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddEntityFramework() .AddSqlServer() .AddDbContext<EfDbContext>(options => { options.UseSqlServer(Configuration["data:ConnectionString"]); }); }
之前是好的,难道又改名了?
果然又改名了, .AddEntityFramework().AddSqlServer() 被合并为 .AddEntityFrameworkSqlServer() 。
这样更简洁了。