
上QQ阅读APP看书,第一时间看更新
Working with the Blog entity
We have discussed in detail the Blog model in Chapter 1, Kickstart - Introduction to Entity Framework Core, but still, the following highlighted part looks pretty new to us:
- The Blog() constructor initializes the Post property, which ensures that the collection has a concrete HashSet list created and ready to accept any new items
- The Post property has a virtual keyword, which instructs EF to lazy load the navigational property Post:
public partial class Blog
{
public Blog()
{
Post = new HashSet<Post>();
}
public int Id { get; set; }
public string Url { get; set; }
public virtual ICollection<Post> Post { get; set; }
}
There is nothing much to explore in the Blog class so, let's move on to the Post class.