EF7 Beta 4: AddEntityFramework does not accept an argument (config)
I am going through this example: http://stephenwalther.com/archive/2015/01/17/asp-net-5-and-angularjs-part-4-using-entity-framework-7
and I am struggling with this piece of code:
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();
}
}
}
The problem is
// Register Entity Framework
services.AddEntityFramework(Configuration)
.AddSqlServer()
.AddDbContext<MoviesAppContext>();
where i am getting build error:
Error CS1501 No overload for method 'AddEntityFramework' takes 1 arguments
In many other examples, I've seen the same use of an argument for configuration.
I don't know what happened ...
source to share
It looks like the tutorial you are following is using an older version of the EF7 framework. EntityFramework 7 beta 4 no longer accepts any parameters AddEntityFramework
. It looks like beta 5 is still on the same track.
I believe what you are looking for:
// Register Entity Framework
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MoviesAppContext>(options =>
{
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString"));
});
This simplifies the structure that you need in the config file because MoviesAppContext
it only requires the connection string, not the EntityFramework
and elements Data
.
source to share