0
I’m having doubts about how to build the relationship between the Client and Sale classes, taking a look at the microsoft website, I was left with doubt if the class should have the navigation for another.
I want the customer to have a list of Sales and that Sales has a list of Itemvenda.
Should I place a property to do the Sale navigation for customer? 'Cause I see that Venda doesn’t need to guard the customer, but the customer keeps his sale.
public class Cliente
{
    public int Id { get; set; }
    public string Nome { get; set; }
    public string Sobrenome { get; set; }
    public string Email { get; set; }
    public DateTime DataCadastro { get; set; }
    public bool Ativo { get; set; }
    public ICollection<Venda> Vendas { get; }
}
public class Venda
{   
    public int Id { get; private set; }
    public DateTime Data { get; private set; }
    public Cliente Cliente { get; set; }
    public int ClienteId { get; set; }
    public ICollection<ItemVenda> ItemVenda { get; }
}
public class ItemVenda
{
    public int Id { get; set; }
    public int IdProduto { get; set; }
    public int IdVenda { get; set; }
    public int Quantidade { get; set; }
    public double Valor { get; set; }
    public virtual Produto Produto { get; set; }
    public ICollection<Produto> Produtos { get; private set; }
}
What is the right way to set them up in Entitytypeconfiguration
public class ConfiguracoesdeCliente : EntityTypeConfiguration<Cliente>
{
    public ConfiguracoesdeCliente()
    {
        HasKey(c => c.Id);
        Property(c => c.Nome)
            .IsRequired()
            .HasMaxLength(150);
        Property(c => c.Sobrenome)
            .IsRequired()
            .HasMaxLength(150);
        Property(c => c.Email)
            .IsRequired();
        //HasMany(p => p.Vendas);
        HasOptional(p => p.Vendas)
            .WithMany()
            .HasForeignKey(p => p.Vendas);
    }
}
public class ConfiguracoesdeVenda : EntityTypeConfiguration<Venda>
{
    public ConfiguracoesdeVenda()
    {
        HasKey(v => v.Id);
        Property(v => v.Data)
            .IsRequired();
        HasMany(v => v.ItemVenda)
            .WithMany();
    }
}
public class ConfiguracoesdeItemVenda : EntityTypeConfiguration<ItemVenda>
{
    public ConfiguracoesdeItemVenda()
    {
        HasKey(p => p.Id);
        Property(p => p.VendaId)
            .IsRequired();
        Property(p => p.ProdutoId)
            .IsRequired();
        Property(p => p.Quantidade)
            .IsRequired();
        Property(p => p.Valor)
            .IsRequired();
        HasRequired(p => p.Venda)
            .WithMany(p => p.ItemVenda);
        HasRequired(p => p.Produto);
        //HasRequired(iv => iv.Venda);
    }
}
What version of the Entity Framework?
– novic
The version is 6.0.0.0
– FelipeDecker