现在我正在学习ADO.NET Entity Framework
并且有一件事我无法向自己解释。以下是我最近使用过的教程的源代码:
public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public User UserId { get; set; }
public virtual List<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public virtual Blog Blog { get; set; }
}
public class User
{
public int UserId { get; set; }
public string Username { get; set; }
public string DisplayName { get; set; }
}
首先,我认为使用List<>
是实现外键式行为的方式,但现在知道我们不需要为什么以及为什么使用List<>
在我们的成员中?
答案 0 :(得分:1)
要显示博客有很多帖子,当您在DB中构建项目时,将关系1xBlog ---&gt; NxPost,其中N =无限制。这将表明每个Blog
可以拥有无限量的Post
s