1
I need to know if my auto relationship and my associative class are created correctly according to the original model made in the SQL Server Diagram.
Original Model - SQL Server
My model in Power Tools
Classe Região
[Table("Regiao")]
public class Regiao
{
[Key]
public long RegiaoID { get; set; }
public string RegiaoDescricao { get; set; }
public virtual ICollection<Territorio> Territorios { get; set; }
}
Class Territory
[Table("Territorio")]
public class Territorio
{
[Key]
public long TerritorioID { get; set; }
public string TerritorioDescricao { get; set; }
public long RegiaoID { get; set; }
[ForeignKey("RegiaoID")]
public virtual Regiao Regiao { get; set; }
public virtual ICollection<TerritorioEmpregado> TerritorioEmpregados { get; set; }
}
Employee class
[Table("Empregado")]
public class Empregado
{
[Key]
public long EmpregadoID { get; set; }
public string PrimeiroNome { get; set; }
public string UltimoNome { get; set; }
public string Titulo { get; set; }
public string TituloDeCortesia { get; set; }
public DateTime DataNascimento { get; set; }
public DateTime DataContratacao { get; set; }
public string Endereco { get; set; }
public string Cidade { get; set; }
public string Regiao { get; set; }
public string CodigoPostal { get; set; }
public string Pais { get; set; }
public string TelefoneResidencial { get; set; }
public string Extensao { get; set; }
public string Notas { get; set; }
public virtual ICollection<TerritorioEmpregado> TerritorioEmpregados { get; set; }
public virtual Empregado Empregado1 { get; set; }
}
Class Associative Territorioemployed
public class TerritorioEmpregado
{
[Key]
public long TerritorioEmpregadoID { get; set; }
public long TerritorioID { get; set; }
[ForeignKey("TerritorioID")]
public virtual Territorio Territorio { get; set; }
public long EmpregadoID { get; set; }
[ForeignKey("EmpregadoID")]
public virtual Empregado Empregado2 { get; set; }
}
Randrade, my Territory class after the modifications got too much navigation property, I don’t know if it was because you did the relationship between Territory and Region. In logic, a region can have several territories, the region would be: South, Southeast, Midwest etc. Another doubt I remained was in relation to the nomenclature of foreign keys, I could not leave with the prefix FK, as your model, yours was much better. I would like you to evaluate my code to see if I did something wrong, my question was edited and the image generated in my Power Tools was updated.
– Kelly Soares
@Kellysoares does not mean to be "boring", but could you return to the original question and open another specific question? His initial question was how to use an associative table, and now he has two other questions derived from this answer. This is normal to happen, but it is better for the community to have the two questions with different doubts, when editing the same.
– Randrade
@Kellysoares I will be happy to answer your questions smoothly. But it would be easier for anyone looking over, if it is better organized.
– Randrade
Sorry Randrade, it is because here does not allow include images in comments, so I edited the question to confirm the changes you suggested, I did not save the previous image to put again. I can change the question if that settles.
– Kelly Soares
I changed the doubt, I hope I improved the mistake I made. Thank you again!
– Kelly Soares
@Kellysoares you did not make any mistakes. This is normal and happens often. I just think it’s best to leave everything organized. But open another question with doubt, which I answer to you with the greatest pleasure.
– Randrade
Randrade, you helped me once to load scripts into ASP.NET MVC, can you figure out the error in this other post I opened? http://answall.com/questions/89144/erro-ao-criar-janela-modal-com-jquery-em-asp-net-mvc
– Kelly Soares