Reputation: 78
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
Upvotes: 2
Views: 905
Reputation: 789
You can tell your DbContext to work with SQL Server (or any provider) in your dbContext. You can do this in two ways:
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
Upvotes: 2