載入相關資料Loading Related Data

Entity Framework Core 可讓您在模型中使用導覽屬性來載入相關實體。Entity Framework Core allows you to use the navigation properties in your model to load related entities. 有三種常見的 O/RM 模式可用來載入相關資料。There are three common O/RM patterns used to load related data.

  • 積極式載入 表示相關的資料會從資料庫載入做為初始查詢的一部分。Eager loading means that the related data is loaded from the database as part of the initial query.
  • 明確載入 表示相關資料會在稍後明確從資料庫載入。Explicit loading means that the related data is explicitly loaded from the database at a later time.
  • 消極式**載入** 表示在存取導覽屬性時,會從資料庫以透明的方式載入相關資料。Lazy loading means that the related data is transparently loaded from the database when the navigation property is accessed.

提示

您可以在 GitHub 上查看本節中的 範例You can view the samples under this section on GitHub.