public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public List<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public Blog Blog { get; set; }
}
modelBuilder.Entity<Post>()
.HasOne(p => p.Blog)
.WithMany(b => b.Posts);
HasOne与WithMany将建立非聚合索引,另外根据类结构的上下文,自动生成2个表之间的外键。
聚集索引一个表只能有一个,而非聚集索引一个表可以存在多个。
参考资料:聚集索引和非聚集索引的区别理解