Well, as far as I can make out, you did the same scheme as in your question and the migration
generated the field names by their default form on their own (Migration has its default way of generating, if you do not put the settings the code generates the names including the relations of its mode), this happens for lack of initial configuration, the important thing is always to do the right, and put the relations as you want, names and ways to not have these problems, although in your case is not a problem is only to do what you need so that it generates a new migration
update to solve the problem.
Minimal example:
Changes shall be made to the classes and rotate again to Migration
[Table("Editora")]
public class Editora
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int EditoraID { get; set; }
public string Nome { get; set; }
public virtual List<Livro> Livros { get; set; }
public virtual List<Telefone> Telefones { get; set; }
}
[Table("Telefone")]
public class Telefone
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int TelefoneID { get; set; }
public string Fixo { get; set; }
public string Cel { get; set; }
public int EditoraID { get; set; }
[ForeignKey("EditoraID")]
public virtual Editora Editora { get; set; }
}
[Table("Livro")]
public class Livro
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int LivroID { get; set; }
public string Titulo { get; set; }
public int EditoraID { get; set; }
[ForeignKey("EditoraID")]
public virtual Editora Editora { get; set; }
}
Ready with this the settings can be updated and with an ideal nomenclature, as:
Do the commands again:
add-migration update3
and then
update-database
Observing: this is the minimum of settings I would recommend the mode Fluent API
, links:
Tip: any changes in your classes that will generate new settings in your base repeat the commands add-migration
and then update-database
that new settings or changes will be applied.
Rename exactly what? Cite a clear example, that is, what happened and you want me to do!
– novic
Like I said, rename foreignKey. Look at my Publisher class, there is a Phone type property which has created a foreign key with the default name, just like to rename it by the first code.
– HeyJoe
What was the name she put in the column of the bank? I mean, the default name ? I just want to understand!
– novic
No Phone was created FK: Editora_editoraid
– HeyJoe
I understand, you have not put the settings and already ran the correct Migration? and now you want to arrange the correct fields names?
– novic
I have already done Migration and update. I want to rename only this foreign key.
– HeyJoe
See my answers to rename it, the same need exist in the settings I did the whole process for you!
– novic
You got it @Heyjoe?
– novic
It seems to me that you do not understand? or understand?
– novic