为了账号安全,请及时绑定邮箱和手机立即绑定

实体框架-包括多个属性级别

实体框架-包括多个属性级别

LEATH 2019-07-06 15:13:31
实体框架-包括多个属性级别include()方法对于对象上的列表非常有效。但如果我需要深入两层呢?例如,下面的方法将返回ApplicationServers,其中包含这里显示的属性。但是,ApplicationsWithOverrideGroup是另一个包含其他复杂对象的容器。我也可以在那个属性上做一个include()吗?或者如何使该属性完全加载?目前,这种方法:public IEnumerable<ApplicationServer> GetAll(){     return this.Database.ApplicationServers         .Include(x => x.ApplicationsWithOverrideGroup)                         .Include(x => x.ApplicationWithGroupToForceInstallList)         .Include(x => x.CustomVariableGroups)                         .ToList();}只填充已启用的属性(下面),而不填充Application或CustomVariableGroup属性(如下)。我该怎么做?public class ApplicationWithOverrideVariableGroup : EntityBase{     public bool Enabled { get; set; }     public Application Application { get; set; }     public CustomVariableGroup CustomVariableGroup { get; set; }}
查看完整描述

3 回答

?
慕盖茨4494581

TA贡献1850条经验 获得超11个赞

如果我正确地理解了您,那么您将询问是否包含嵌套属性。如果是这样的话:

.Include(x => x.ApplicationsWithOverrideGroup.NestedProp)

.Include("ApplicationsWithOverrideGroup.NestedProp")

.Include($"{nameof(ApplicationsWithOverrideGroup)}.{nameof(NestedProp)}")


查看完整回答
反对 回复 2019-07-06
  • 3 回答
  • 0 关注
  • 420 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信