Database
If dotnet ef
has not been installed, install it as a global tool:
.NET CLICopy
dotnet tool install --global dotnet-ef
For more information on the CLI for EF Core, see EF Core tools reference for .Net CLI.
Run the following .NET CLI commands:
.NET CLICopy
dotnet ef migrations add InitialCreate
dotnet ef database update
ef migrations add InitialCreate
: Generates an _Migrations/{timestamp}InitialCreate.cs migration file. TheInitialCreate
argument is the migration name. Any name can be used, but by convention, a name is selected that describes the migration. This is the first migration, so the generated class contains code to create the database schema. The database schema is based on the model specified in theMvcMovieContext
class, in the Data/MvcMovieContext.cs file.ef database update
: Updates the database to the latest migration, which the previous command created. This command runs theUp
method in the _Migrations/{time-stamp}InitialCreate.cs file, which creates the database.
EF CLI
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet ef migrations add InitialCreate
dotnet ef database update
Your startup project 'AuthorizeServer' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
SQLite
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
using Microsoft.EntityFrameworkCore;
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
}
Related Ref:
Get started with ASP.NET Core MVC