现在我正在学习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; }
}
首先,我认为使用 ofList<>
是实现类似外键的行为的方式,但现在知道这不是我们需要的原因以及我们在实体中使用List<>
的目的是什么?