【发布时间】:2014-05-05 12:51:48
【问题描述】:
我刚开始使用 EF Code First。我有一个关于这个的问题。通过 Fluent API 定义关系有什么优势?
当我从我的 poco(或实体)创建数据库时,我的表之间已经有了一对多和/或多对多的关系。
例如:
public class School
{
public School()
{
Students = new List<Student>();
}
public Guid Id { get; set; }
public string Name { get; set; }
public List<Student> Student{ get; set; }
}
public class Student
{
public Guid Id { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public Guid SchoolId{ get; set; }
public School School{ get; set; }
}
这已经在学生和学校之间建立了关系。通过 Fluent API 定义关系是否有优势?还是不行?
提前致谢!
【问题讨论】:
标签: c# entity-framework ef-code-first