I am creating a new web site from an empty ASP.NET Core 2 template and following the Microsoft Entity Framework Tutorial to help me get setup. At one point it has you add the code:
services.AddDbContext<SchoolContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
To the ConfigureServices()
method of Startup.cs
. I did this but in my project Visual Studio give me that little red line under Configuration
in the Configuraiton.GetConnectionString
I had thought I was missing a using
statement or even a package but the Visual Studio 2017 quick actions don't identify a using
statement to use and I do have the Microsoft.AspNetCore.All
package installed so I should have all the packages.
What am I missing that is making the Configuration
not recognized?
Edit: The error is:
The name 'Configuration' does not exist in the current context
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<CollectionContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc();
}
Configuration
is not static. It should be an instance variable/property of theStartup
class. – ThatcherRick Anderson
should start practicing what he teaches... it is frustrating to follow non-working guides... – Battery