In the Fluent API, you can name the FK columns:
modelBuilder.Entity<Setor>() .HasOptional(s => s.Secretaria) .WithMany() .Map(a => a.MapKey("SecretariaId"));
I think this is not possible in DataAnnotations. In addition, you can open the foreign key in your model class, for example:
public class Setor : Entity { public long Id { get; set; } public string Nome { get; set; } public long? SecretariaId { get; set; } public virtual Secretaria Secretaria { get; set; } }
Conventions will recognize this automatically, since FK and the column name will be the name of the property, i.e. SecretariaId .
Slauma
source share