'EF Core reference the same table twice
Good morning everybody.
I am working on a proof of concept project at the moment and I have hit a little bit of a speed bump.
I am trying to reference the same model/class/entity twice within my model. The training video told me to create the entry twice once with a prefix of Id for the foreign key and another without the Id prefix for the navigational element. However, when I create the migration I am getting the foreign key created twice, for example GenderId and GenderId1. What am I doing wrong? Or did I misunderstand the video?
public class Customer
{
[Key]
public Guid Id { get; set; }
[Required]
public SystemAttributeValue TitleId { get; set; }
[Required]
public SystemAttributeValue GenderId { get; set; }
[Required]
[Display(Name = "First Name")]
[MaxLength(50)]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
[MaxLength(50)]
public string LastName { get; set; }
//Navigational Properties
public SystemAttributeValue Title { get; set; }
public SystemAttributeValue Gender { get; set; }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
