在 EF Core 中定义一对多关系的最佳实践是什么?
是否建议一般使用列表,因为它们提供更多功能?然后是接口 IList 而不是 List,因为它没有定义实现?如果确实重要,我应该根据什么标准选择其中之一?
Microsoft 建议使用以下 https://docs.microsoft.com/en-us/ef/core/modeling/relationships
public class Blog
{
public int BlogId { get; set; }
public List<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然而
https://www.learnentityframeworkcore.com/configuration/one-to-many-relationship-configuration 建议 ICollections
以下 2011 年的答案在 EF Core 中仍然有效吗?