0

I have table name is Grades which have a column name Upgrade refer to value which is will be one of the values of the primary key in the table Grades - same table- I try to do this like the following code

public class Grades
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public Grades UpGrade { get; set; }
        public int UpGradeId { get; set; }
    }
Eman Abbas
  • 23
  • 7

1 Answers1

0

[ForeignKey] attribute should work just as well for self-referencing FKs as it works for regular ForeignKeys

public class Grades
{
    public int Id { get; set; }
    public string Name { get; set; }
    [ForeignKey("UpGradeId")]
    public Grades UpGrade { get; set; }
    public int UpGradeId { get; set; }
}
Eugene Podskal
  • 10,270
  • 5
  • 31
  • 53