根据我的 Visual Studios 请求,我使用 Entity Framework Core (1.0.1) 开始了我的最新项目
因此,编写我的数据库模型时,我总是使用“虚拟”说明符来启用列表的延迟加载。尽管在加载父表时,子列表似乎从未加载。
父模型
public class Events
{
[Key]
public int EventID { get; set; }
public string EventName { get; set; }
public virtual List<EventInclusions> EventInclusions { get; set; }
}
儿童模型
public class EventInclusions
{
[Key]
public int EventIncSubID { get; set; }
public string InclusionName { get; set; }
public string InclusionDesc { get; set; }
public Boolean InclusionActive { get; set; }
}
向这些表添加新记录似乎很有效,因为我习惯了可以将 EventInclusions 记录作为列表嵌套在事件记录内。
虽然当我查询这张表时
_context.Events.Where(e => e.EventName == "Test")
问题
无论幕后数据如何,EventInclusions 都将返回空值。
读了一下之后,我感觉这是我通常使用的 EF6 和 EF Core 之间的变化
我可以使用一些帮助来制作一揽子延迟加载声明或找出指定延迟加载的新格式。
Caz
延迟加载现在可用于EF Core 2.1
这是相关文档的链接:
https://learn.microsoft.com/en-us/ef/core/querying/lated-data#lazy-loading https://learn.microsoft.com/en-us/ef/core/querying/related-data#lazy-loading
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)