Creating FK's with EntityFramework + Fluent-API - ASP.NET MVC

0

I have some questions about creating FKs with the Fluent API

  

For example: I have the class Cliente and Endereco , and the client can have more than 1 address, but the address can only belong to 1 client, so I would like to create a new table for this, because this class Endereco will be used for other classes that can also have address. (New class RelacaoClienteEndereco ).

public class Endereco : EntityBase
{
    public Endereco()
    {

    }

    public string CEP { get; set; }
    public string Logradouro { get; set; }
    public string Numero { get; set; }
    public string Complemento { get; set; }
    public string Bairro { get; set; }
    public string Estado { get; set; }
    public string Cidade { get; set; }
    public TipoEndereco TipoEndereco { get; set; }
    public bool EnderecoCorrespondencia { get; set; }
}

public class Cliente
{
    public int ID { get; set; }
    public string NomeCompleto { get; set; }

    public virtual ICollection<Domain.Cadastros.Endereco> Enderecos { get; set; }
}

How to do FK in this case with the Fluent API?

    
asked by anonymous 19.07.2018 / 15:36

0 answers