locked
How to define PK and FK on single column RRS feed

  • Question

  • User828542847 posted

    just add a example here if possible.

    Friday, July 21, 2017 12:47 PM

Answers

  • User828542847 posted

    i got a sample where PK and FK is used for single column

        [Key, ForeignKey("Student")]
        public int StudentId { get; set; }

    public class Student
    {
        public Student() { }
    
        public int StudentId { get; set; }
        public string StudentName { get; set; }
    
        public virtual StudentAddress Address { get; set; }
    
    }
         
    public class StudentAddress 
    {
        [Key, ForeignKey("Student")]
        public int StudentId { get; set; }
            
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string City { get; set; }
        public int Zipcode { get; set; }
        public string State { get; set; }
        public string Country { get; set; }
    
        public virtual Student Student { get; set; }
    }
            

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 21, 2017 12:48 PM