【发布时间】:2016-02-16 10:11:58
【问题描述】:
我正在使用 Linq 从上下文中检索数据。我试图只获取没有孙子AttributeItems 的父项CategoryAttributeItemDescriptions 的内部名称包含单词“Range -”
下面的代码是我目前所在的位置。
var query = from caid in context.CategoryAttributeItemDescriptions
join cai in context.CategoryAttributeItems on caid.Id equals cai.CategoryAttributeItemDescriptionsId
join ai in context.AttributeItems on cai.AttributeId equals ai.Id
where caid.CategoryAttributeItems.Any(c => !c.AttributeItem.InternalName.Contains("Range -")) && caid.CategoryId ==element.Id
select caid;
问题在于返回的父母仍然与具有该内部名称的孙子有关系。有任何想法吗? 谢谢
【问题讨论】:
-
尝试将 where 子句更改为 'where caid.CategoryAttributeItems.Any(c => !c.AttributeItem.InternalName.Contains("Range -")) && caid.CategoryId ==element.Id'
-
基本上在 c.AttributeIte.... 之前添加感叹号。这意味着'Not'
-
我可能在上面读错了,但你不是在 Any() 谓词中寻找 FOR 匹配,而不是排除??
-
我添加了感叹号(愚蠢的错误),但是,它仍然只忽略所有孙子都使用这个内部名称的父母,而不是例如只有一个的父母。