dotnet tool install --global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.DesignAdd class like below to project.
public class DataContext : DbContext
{
public DataContext(DbContextOptions options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(@"Data Source=DBName.db");
}
// list Dbset Below to use
}Add ef service to Program.cs:
builder.Services.AddDbContext<DataContext>();//(Option way)
builder.Services.AddSqlite<DataContext>(builder.Configuration.GetConnectionString("DefaultConnection"));dotnet ef migrations add InitialCreate
dotnet ef database updateSeeding can be set in OnConfiguring method of the DbContext subclass:
optionsBuilder.UseSeeding((context, _) =>
// use context to prepare data
);After executing dotnet ef database update, UseSeeding method will be triggered.