<分区>
我正在使用 EntityFramework Core 1.1.0。我可以查询表并加载实体,但 Microsoft 的说明指示如果我想加载关系数据,我应该使用 .Include()
函数:
https://learn.microsoft.com/en-us/ef/core/querying/related-data
You can use the
Include
method to specify related data to be included in query results. In the following example, the blogs that are returned in the results will have theirPosts
property populated with the related posts.using (var context = new BloggingContext()) { var blogs = context.Blogs .Include(blog => blog.Posts) .ToList(); }
我没有 .Include()
选项。
知道为什么缺少这个或如何加载外键关系数据吗?
this.context.Mail
.Include("Files") // This is missing
我已经求助于显式加载关系数据。这对于小结果集来说很好,但随着我的数据集的增长,这会让我很伤心。
var mails = this.context.Mail.ToList();
mails.ForEach(mail =>
{
this.context.Entry(mail)
.Collection(m => m.Files)
.Load();
});