こんにちは、私はこのコードを書くときに上書きすることが見つかりませ適切な方法を受けていないよC#EFのマイグレーションクラスでオーバーライドするSeedメソッドがないのはなぜですか?
保護されたオーバーライド無効種子(MuziekApp.MuziekContextコンテキスト){}私はオーバーライドする種子メソッドを持っていない来るどのよう
私の移行?何が間違っているのか、間違っているのですか?
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;
namespace MuziekApp.Migrations
{
public partial class Second : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
protected override void Seed(MuziekApp.MuziekContext context)
{
List<Artiest> lijst = new List<Artiest>()
{
new Artiest() { ArtiestID = 1, Naam = "Jane", InstrumentID = 1, InstrumentNaam = "Saxofoon", PopgroepID = 1, GroepNaam = "Killers"},
new Artiest() { ArtiestID = 2, Naam = "Charles", InstrumentID = 2, InstrumentNaam = "Gitaar", PopgroepID = 1, GroepNaam = "Killers"},
new Artiest() { ArtiestID = 3, Naam = "Miguel", InstrumentID = 1, InstrumentNaam = "Saxofoon", PopgroepID = 2, GroepNaam = "Rock"},
new Artiest() { ArtiestID = 4, Naam = "John", InstrumentID = 2, InstrumentNaam = "Gitaar", PopgroepID = 2, GroepNaam = "Rock" }
};
List<Instrument> lijst2 = new List<Instrument>()
{
new Instrument() { InstrumentID = 1, InstrumentNaam = "Saxofoon"},
new Instrument() { InstrumentID = 2, InstrumentNaam = "Gitaar"}
};
List<Popgroep> lijst3 = new List<Popgroep>()
{
new Popgroep() { PopgroepID = 1, GroepNaam = "Killers"},
new Popgroep() { PopgroepID = 2, GroepNaam = "Rock"}
};
context.Artiesten.AddRange(lijst);
context.Instrumenten.AddRange(lijst2);
context.Popgroepen.AddRange(lijst3);
}
}
}
EFコアにはシードメソッドがありません。 – DavidG
「Migration」のように、ドキュメントに記載された「Seed」メソッドがありません。https://docs.microsoft.com/en-us/ef/core/api/microsoft.entityframeworkcore.migration.migration – juharr
次にシードメソッドを使用しますか? –