Self Join

8 views
Skip to first unread message

Carl

unread,
Apr 12, 2013, 10:05:55 AM4/12/13
to dbl...@googlegroups.com
Hi,

I am trying to do a parent/child join on the same entity (same SQL table) in this format:

EntityType1[] = DataContext.EntityType1.Join(
EntityType1,
EntityParent => EntityParent.ID,
EntityChild => EntityChild.ParentID,
(EntityParent, EntityChild) => new { EntityParent, EntityChild }
 ).Select(obj => obj.EntityChild).ToArray();

Obviously this is pseudo and I have a reason for doing the join in my where clause, I am having a problem where the query generated appears to come out with the parent object on both sides of this join, see below:

 SELECT EntityChild.* FROM EntityType1 EntityParent, EntityType1 EntityChild WHERE EntityParent.ID = EntityParent.ParentID

Is there some syntax I have missed to alias the second instance of the Entity Type or is this a problem with the query generation?

Thanks,
Carl
Reply all
Reply to author
Forward
0 new messages