Linq to Entities, checking for specific foreign key id?

Posted by AaronLS on Stack Overflow See other posts from Stack Overflow or by AaronLS
Published on 2010-05-24T16:19:07Z Indexed on 2010/05/24 17:31 UTC
Read the original article Hit count: 299

Filed under:
|

I am trying to get rows where the foreign key ParentID == 0, and this is what I am trying but I get a NotSupportedException because it can't translate the ArrayIndex [0]:

IQueryable<ApplicationSectionNode> topLevelNodeQuery =
    from n in uacEntitiesContext.ApplicationSectionNodeSet
    where (int)n.Parent.EntityKey.EntityKeyValues[0].Value == 0
    orderby n.Sequence
    select n;

So I need to pull that ArrayIndex out of the query so that the runtime can successfully translate the query. I'm not sure how to do that though. How does one query a specific object via it's primary key or set of objects via foreign key?

Edit: Note that there is not actually a row in the table with NodeId == 0, the 0 is a magic value(not my idea) to indicate top level nodes. So I can't do n.Parent.NodeId == 0

© Stack Overflow or respective owner

Related posts about c#

Related posts about entity-framework