multiple “1 to 0..1” relationship models

孤人 提交于 2019-12-06 15:05:02

Doesn't look like EF supports real 1 to 0..1 relationship. You need a foreign key. And add the optional (int?) into the main model.

So I did this as follow, and it works like a charm.

public class Instructor
{
    public Int InstructorID { get; set; }
    public string LastName { get; set; }
    public string FirstMidName { get; set; }

    public int? OfficeAssignmentID { get; set; }
    public virtual OfficeAssignment OfficeAssignment { get; set; }

    public int? HomeID { get; set; }
    public virtual Home Home { get; set; }

}

public class OfficeAssignment
{
    public int OfficeAssignmentID { get; set; }
    public string Location { get; set; }

}

public class Home
{
    public int HomeID { get; set; }
    public string Location { get; set; }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!