我试图向下过滤三个级别,然后找到PropertyMailingAddress.Status == True。
它仍然返回PropertyMailingAddress.Status下的False值。
如何将过滤器转换为三个级别并进行嵌套过滤?
.Where(a => propertyIds.Contains(a.PropertyId)
&& a.PropertySitusAddress.Any(x => x.Status.HasValue && x.Status.Value)
&& a.PropertyParty.Any(
x => (x.Status.HasValue && x.Status.Value)
&& (x.Party.Status.HasValue && x.Party.Status.Value)
)
//This line is not working, still returning false status values
&& a.PropertyParty.Any(x=> (x.Party.PartyMailingAddress.Any(z => z.PropertyMailingAddress.Any(h => h.Status.HasValue && h.Status.Value))))
)
.ToListAsync();
当前的SQL事件探查器:(请参阅下面的内容)
WHERE ([x20].[Status] IS NOT NULL AND ([x20].[Status] = 1)) AND ([a6].[PropertyId] = [x20].[PropertyId]))) AND EXISTS (
SELECT 1
FROM [PM].[PropertyParty] AS [x21]
LEFT JOIN [PM].[Party] AS [x.Party13] ON [x21].[PartyId] = [x.Party13].[PartyId]
WHERE (([x21].[Status] IS NOT NULL AND ([x21].[Status] = 1)) AND ([x.Party13].[Status] IS NOT NULL AND ([x.Party13].[Status] = 1))) AND ([a6].[PropertyId] = [x21].[PropertyId]))) AND EXISTS (
SELECT 1
FROM [PM].[PropertyParty] AS [x22]
LEFT JOIN [PM].[Party] AS [x.Party14] ON [x22].[PartyId] = [x.Party14].[PartyId]
WHERE EXISTS ( // Where Exists is here; trying to convert to Where
SELECT 1
FROM [PM].[PartyMailingAddress] AS [z6]
**WHERE EXISTS** ( // Where Exists is here; trying to convert to Where Only
SELECT 1
FROM [PM].[PropertyMailingAddress] AS [h6]
WHERE ([h6].[Status] IS NOT NULL AND ([h6].[Status] = 1)) AND ([z6].[PartyMailingAddressId] = [h6].[PartyMailingAddressId])) AND ([x.Party14].[PartyId] = [z6].[PartyId])) AND ([a6].[PropertyId] =