Reputation: 559
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 code part:
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 with
// Register Entity Framework
services.AddEntityFramework(Configuration)
.AddSqlServer()
.AddDbContext<MoviesAppContext>();
where i get a build error:
Error CS1501 No overload for method 'AddEntityFramework' takes 1 arguments
I saw in a lot of other examples the same use of a argument for Configuration.
No idea, what's wrong....
Upvotes: 3
Views: 2897
Reputation: 11932
It looks like the tutorial you're following is using an older version of the EF7 framework. EntityFramework 7 beta 4 no longer accepts any parameters to AddEntityFramework
. It looks like beta 5 is still on this same track, too.
I believe what you're looking for is this:
// 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 configuration file, because the MoviesAppContext
only needs the connection string, not the EntityFramework
and Data
elements.
Upvotes: 3