Answer the question
In order to leave comments, you need to log in
Insert into table during migration?
I deployed the project to .NET Core. In the first migration, I initialized the tables. Roles, rights, users. Now, using the same migration, I want to create a record in one of the tables. The problem is that in the body of the migration class, writing to the table is not possible.
namespace ApsNetCore.Data.Migrations
{
public partial class CreateIdentitySchema : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
Answer the question
In order to leave comments, you need to log in
You can add entries to the Seed method.
More or less like this:
protected override void Seed(BookService.Models.BookServiceContext context)
{
context.Authors.AddOrUpdate(x => x.Id,
new Author() { Id = 1, Name = "Jane Austen" },
new Author() { Id = 2, Name = "Charles Dickens" },
new Author() { Id = 3, Name = "Miguel de Cervantes" }
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question