dotnet ef migrations {name} dotnet ef database update

c# entity-framework-core

Question

I am learning Entity Framework core and code first today, by following a video on pluralsite to create my own dbcontext. My project does create a database, but it is not doing it in SQL Server. When I create a context instance and look, it says database facade so I assume it is in memory. Where can I change a flag, or set a digit somewhere in the thousands of lines of boiler plate of dot net core, to make it create the database in sql server, and not in memory?

I used the command line to attempt to create it.
dotnet ef migrations {name} dotnet ef database update

1
1
10/13/2016 11:10:13 PM

Popular Answer

You can tell your DbContext to work with SQL Server (or any provider) in your dbContext. You can do this in two ways:

  1. By using dependency injection
  2. By overriding the OnConfiguring method (Override in your Context class)

This is an example of overriding the OnConfiguring method

protected override void OnConfiguring(DbContextOptionsBuilder optionbuilder)
{
    string connectionString = @"Server=localhost;Database=YourDataBaseName;Trusted_Connection=true;"
    optionbuilder.UseSqlServer(connectionString);
}

Be sure to check out https://docs.efproject.net/en/latest/miscellaneous/configuring-dbcontext.html and https://docs.efproject.net/en/latest/providers/sql-server/index.html for more info

0
10/13/2016 11:42:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow