Boa noite!
Fiz tudo conforme a orientação: criei as classes Produto, Promocao e PromocaoProduto com os dois Ids 'ProdutoId' e 'PromocaoId', depois criei o método OnModelCreating na classe LojaContext para gerar a chave composta na classe PromocaoProduto.
Após rodar o Add-Migration Promocao apareceu esse campo 'PromocaoId1' na migração:
namespace Alura.Loja.Testes.ConsoleApp.Migrations
{
public partial class Promocao : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Promocoes",
columns: table => new
{
Id = table.Column<string>(nullable: false),
DataFim = table.Column<DateTime>(nullable: false),
DataInicio = table.Column<DateTime>(nullable: false),
Descricao = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Promocoes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PromocaoProduto",
columns: table => new
{
PromocaoId = table.Column<int>(nullable: false),
ProdutoId = table.Column<int>(nullable: false),
PromocaoId1 = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PromocaoProduto", x => new { x.PromocaoId, x.ProdutoId });
table.ForeignKey(
name: "FK_PromocaoProduto_Produtos_ProdutoId",
column: x => x.ProdutoId,
principalTable: "Produtos",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PromocaoProduto_Promocoes_PromocaoId1",
column: x => x.PromocaoId1,
principalTable: "Promocoes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_PromocaoProduto_ProdutoId",
table: "PromocaoProduto",
column: "ProdutoId");
migrationBuilder.CreateIndex(
name: "IX_PromocaoProduto_PromocaoId1",
table: "PromocaoProduto",
column: "PromocaoId1");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PromocaoProduto");
migrationBuilder.DropTable(
name: "Promocoes");
}
}
}
O que fiz de errado?