You can't compare a related table to null
directly. Instead, compare against your foreign key member (assuming that PrimaryTable
reference RelatedTable
using a member called RelatedTableId
.
sites.Where(s => s.RelatedTableId != null && s.RelatedTable.Any(
p => p.Name == param1.ToLower() && p.PolicyType == "primary"));
You may even be able to get away with removing the null check completely. Since this query is run against the database, you won't get a NullReferenceException
and it may work. You'll have to double check on that though.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…