I am on a MAC using .NET Core 2.0
My program.cs
file is set you the environment set which is development on my machine
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
//.UseStartup<Startup>()
.UseStartup("MoviesLibfrary")
.Build();
I have a new class called StartupDevelopment
:
public class StartupDevelopment
{
public StartupDevelopment(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<MvcTriviaContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("MvcTriviaContext")));
}
}
Debugging the application does use the StartupDevelopment
class.
Using dotnet ef migrations add InitialCreate
and dotnet ef database update
is trying to use SQL Server.
Error I get when running database upgrade
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 25 - Connection string is not valid)
Connection string in appsettings.Development.json
:
"ConnectionStrings": {
"MvcTriviaContext": "Data Source=Data\\databasename.db"
}
How do I use dotnet ef
with sqlite as my development environment is specified to use sqlite?