我正在使用 EntityFramework Core 1.1.0。我可以查询表并加载实体,但 Microsoft 的说明表明如果我想加载关系数据,我应该使用.Include()
功能:
https://learn.microsoft.com/en-us/ef/core/querying/lated-data https://learn.microsoft.com/en-us/ef/core/querying/related-data
您可以使用Include
方法指定要包含在查询结果中的相关数据。在以下示例中,结果中返回的博客将具有其Posts
属性填充了相关帖子。
using (var context = new BloggingContext())
{
var blogs = context.Blogs
.Include(blog => blog.Posts)
.ToList();
}
我没有.Include()
option.
有什么想法为什么缺失或如何加载外键关系数据吗?
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();
});
您是否包含了正确的名称空间?
从文档中链接的存储库 https://github.com/aspnet/EntityFramework.Docs/blob/master/samples/core/Querying/Querying/RelatedData/Sample.cs:
using Microsoft.EntityFrameworkCore;
using System.Linq;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)