在Code First Fluent API中定义关系 [英] Defining relationships in Code First Fluent API
本文介绍了在Code First Fluent API中定义关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚开始使用EF Code First。我对此有疑问。通过Fluent API定义关系有什么好处?
当我从我的poco(或实体)创建数据库时,我已经有了一对多和/或我的表之间的多对多关系。
例如:
Hi,
I just started with EF Code First. And I have a question about this. What is the advantage of defining relationships through the Fluent API?
When I create the database from my poco's (or entities) I already have one-to-many and/or many-to-many relationships between my tables.
For ex:
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定义关系是否有优势?或者不是吗?
提前致谢!
This creates already a relationship between Students and School. Does defining a relationship through the Fluent API gives advantages? Or not?
Thanks in advance!
推荐答案
这篇关于在Code First Fluent API中定义关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文