如何在 Entityframework 中映射 ManyToOne 或 OneToMany
How to map ManyToOne or OneToMany in Entityframework
我是第一次使用Entity Framework,我的问题是:
你如何映射 ManyToOne 或 OneToMany ,就像 java 中的 hibernate,和 Entity 因为在例子中我不太明白?
谢谢
考虑以下学生和标准实体。
public class Student
{
public Student() { }
public int StudentId { get; set; }
public string StudentName { get; set; }
public virtual Standard Standard { get; set; }
}
public class Standard
{
public Standard()
{
Students = new List<Student>();
}
public int StandardId { get; set; }
public string Description { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
在上面的示例中,学生实体包括导航 属性 标准,而标准实体包括学生的集合 属性。这是形成一对多关系的默认约定。
希望这会有所帮助
我是第一次使用Entity Framework,我的问题是:
你如何映射 ManyToOne 或 OneToMany ,就像 java 中的 hibernate,和 Entity 因为在例子中我不太明白?
谢谢
考虑以下学生和标准实体。
public class Student
{
public Student() { }
public int StudentId { get; set; }
public string StudentName { get; set; }
public virtual Standard Standard { get; set; }
}
public class Standard
{
public Standard()
{
Students = new List<Student>();
}
public int StandardId { get; set; }
public string Description { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
在上面的示例中,学生实体包括导航 属性 标准,而标准实体包括学生的集合 属性。这是形成一对多关系的默认约定。
希望这会有所帮助