Como visto no vídeo: Comecei incluindo o Produto
no modelBuilder
, criei uma migração e rodei através do Update-Database
a tabela foi criada.
Quando fui incluir as outras entidades, deste jeito:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Produto>()
.HasKey(t => t.Id);
modelBuilder.Entity<Pedido>()
.HasKey(t => t.Id);
modelBuilder.Entity<Pedido>()
.HasMany(t => t.Itens)
.WithOne(t => t.Pedido);
modelBuilder.Entity<Pedido>()
.HasOne(t => t.Cadastro)
.WithOne(t => t.Pedido)
.IsRequired();
modelBuilder.Entity<ItemPedido>()
.HasKey(t => t.Id);
modelBuilder.Entity<ItemPedido>()
.HasOne(t => t.Pedido);
modelBuilder.Entity<ItemPedido>()
.HasOne(t => t.Produto);
modelBuilder.Entity<Cadastro>()
.HasKey(t => t.Id);
modelBuilder.Entity<Cadastro>()
.HasOne(t => t.Pedido);
}
Ao tentar rodar o comando Add-Migration Model
, recebi a seguinte mensagem de erro:
The child/dependent side could not be determined for the one-to-one relationship between 'Pedido.Cadastro' and 'Cadastro.Pedido'. To identify the child/dependent side of the relationship, configure the foreign key property. If these navigations should not be part of the same relationship configure them without specifying the inverse. See http://go.microsoft.com/fwlink/?LinkId=724062 for more details.
Alguém pode me ajudar?