How to name the foreign key in the Entity framework

Asked

Viewed 212 times

4

public class Lancamento {

     // Colunas e métodos omitidos 

     [Column("IdContaBancaria")]
     public virtual ContaBancaria ContaBancaria { get; set; }
}

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

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

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

How to set foreign key name ?

1 answer

2


Using the attribute Foreignkey:

[ForeignKey("fk_nome")]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.