How to declare one to one relationship using Entity Framework 4 Code First (POCO)

后端 未结 4 1767
轻奢々
轻奢々 2020-11-27 17:00

How to declare a one to one relationship using Entity Framework 4 Code First (POCO)?

I found this question (one-to-one relationships in Entity Framework 4) , but the

4条回答
  •  甜味超标
    2020-11-27 17:22

    public class User
    {
        public int Id { get; set; }
        public string Username { get; set; }
    
        public virtual Profile Profile { get; set; }
    }
    
    public class Profile
    {
        public int Id { get; set; }
    
        public int UserID { get; set; }
    
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string PostalCode { get; set; }
    }
    

    Add the virtual Profile and the UserID and I think that should get you there.

提交回复
热议问题