小编raw*_*raw的帖子

对 EF Core 中的 1 到 n 关系使用 IList、List、ICollection

在 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)

然而

http://www.entityframeworktutorial.net/efcore/configure-one-to-many-relationship-using-fluent-api-in-ef-core.aspx

https://www.learnentityframeworkcore.com/configuration/one-to-many-relationship-configuration 建议 ICollections

以下 2011 年的答案在 EF Core 中仍然有效吗?

/sf/answers/535918211/

c# database entity-framework list icollection

5
推荐指数
1
解决办法
3777
查看次数

标签 统计

c# ×1

database ×1

entity-framework ×1

icollection ×1

list ×1