我想获得其中的外键PARENTID == 0,这就是我想要的行,但我得到NotSupportedException异常,因为它无法翻译ArrayIndex [0]
:Linq to Entities,检查特定的外键ID?
IQueryable<ApplicationSectionNode> topLevelNodeQuery =
from n in uacEntitiesContext.ApplicationSectionNodeSet
where (int)n.Parent.EntityKey.EntityKeyValues[0].Value == 0
orderby n.Sequence
select n;
所以我需要将该ArrayIndex拉出查询,以便运行时可以成功转换查询。我不知道该怎么做。如何通过外键通过主键或对象组来查询特定对象?
编辑:请注意,表中实际上没有一行中的NodeId == 0,0是一个魔术值(不是我的想法)来指示顶级节点。所以我不能做n.Parent.NodeId == 0
你试过“哪里n.Parent == null”? – 2010-05-24 16:45:24
@Mattias实际上有效。我不认为这是因为制作数据库的人使用的值为0而不是null。请将此作为答案发布,我会将其标记为已接受。 – AaronLS 2010-05-24 17:21:32