[英]What do navigation properties do in Entity Framework?
I use EF6 and these are my POCO's. 我使用EF6,这些是我的POCO。
public class Author
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Book
{
public int Id { get; set; }
[Required]
public string Title { get; set; }
public int Year { get; set; }
public decimal Price { get; set; }
public string Genre { get; set; }
// Foreign Key
public int AuthorId { get; set; }
// Navigation property
public Author Author { get; set; }
}
Author
? Author
什么? virtual
? virtual
什么意义? EDIT: after a bit more research I've found this thread , which nicely answer my first question. 编辑:经过更多的研究,我发现了这个线程 ,很好地回答了我的第一个问题。
Can people help with the last two questions please? 人们可以帮您解决最后两个问题吗?
2: if you do virtual navigation properties then will work lazy load value of this property: 2:如果您执行虚拟导航属性,则该属性的延迟加载值将起作用:
public class Book
{
//...
public int AuthorId { get; set; }
public virtual Author Author { get; set; }
}
It work: EF create proxy to your entity (Book) and overrides navigation property (Author). 它的工作原理是:EF为您的实体(书)创建代理,并覆盖导航属性(作者)。 When you load entity (Book) of the database value of the navigation property (Author) is not load.
当您加载数据库的实体(Book)时,导航属性(Author)的值也不会加载。 Only the first get value of navigation property (Author), it will be load ( http://blogs.msdn.com/b/adonet/archive/2009/12/22/poco-proxies-part-1.aspx ).
只有导航属性(Author)的第一个获取值会被加载( http://blogs.msdn.com/b/adonet/archive/2009/12/22/poco-proxies-part-1.aspx )。
3: inherently navigation properties is no specific to Entity Framework. 3:固有的导航属性并不特定于实体框架。 This link to other entities.
此链接到其他实体。 But term "navigation properties" is specific to EF.
但是术语“导航属性”特定于EF。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.