c# – How to name foreign key in Entity framework


public class Lancamento {

     // Colunas e métodos omitidos 

     public virtual ContaBancaria ContaBancaria { get; set; }

public class ContaBancaria
        [Key] // PK
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)] // Será auto incremento
        public int IdContaBancaria { get; set; }   

        public virtual ICollection<Lancamento> LancamentosCB { get; set; }
       // Colunas e métodos omitidos 

I would like to make the name of the fk explicit but the name always generated [ContaBancaria_IdContaBancaria]

How to set foreign key name?


Using the ForeignKey attribute:

Scroll to Top