假设我有以下两种型号:
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; }
}
现在,如果我想在DbContext中配置模型关系,那么:
之间有什么区别?
modelBuilder.Entity<Post>()
.HasOne(p => p.Blog)
.WithMany(b => b.Posts);
和
modelBuilder.Entity<Blog>()
.HasMany(b => b.Posts)
.WithOne(p => p.blog);