我有这个问题:
var mapping = await context.MAPPING_COMPANIES
.Include(x => x.CUSTOMER_INFO)
.SingleOrDefaultAsync(where => where.AMIN_COMPANY_ID == aminCompanyId);
现在,单个MAPPING_COMPANY
将只有一个CUSTOMER_INFO
。我还需要包含另外两个CUSTOMER_INFO
:MASTER_ADDRESS_TYPE
和MASTER_CUSTOMER_STATUS
的实体。我需要使用CUSTOMER_INFO
包含或展平这两个。
我该怎么做?我已经尝试了更多Including语句并结合了Selects,甚至尝试了ThenIncludeBy.EF6 nuget,但无济于事。
答案 0 :(得分:1)
你试过这个吗?
var mapping = await context.MAPPING_COMPANIES
.Include(x => x.CUSTOMER_INFO)
.Include(x => x.CUSTOMER_INFO.MASTER_ADDRESS_TYPE)
.Include(x => x.CUSTOMER_INFO.MASTER_CUSTOMER_STATUS)
.SingleOrDefaultAsync(where => where.AMIN_COMPANY_ID == aminCompanyId);
您需要确保自己没有Select()
,或者我认为GroupBy()
,因为只有在查询形状与实体集匹配时,Include()才有效。