SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 lists, one list contains a lookup to another.

I have used SPMetal to generate entity.cs based on this article:

I don't think I need to go the object LINQ route, as in the article because I have a lookup field on which I want to base the join.

I've gotten this far:

EntityDataContext site = new EntityDataContext(this.SiteURL);
site.ObjectTrackingEnabled = false;

EntityList<ListA> listAItems = site.GetList<ListA>(ListAName);
EntityList<ListB> listBItems = site.GetList<ListB>(ListBName);

This works so far and gives 2 flat EntityLists for both Sharepoint Lists.

From this point on, how would I create a query to just join, based on the lookup field?


If I was doing it in SQL, this is the statement I would be writing:

Select [fields] from table1 AA inner join table2 BB on AA.lookupfield = AA.Title/ID where BB.field = $inputFromUser
share|improve this question
up vote 2 down vote accepted

At the end of blog post you can find how to join and query two lists.

Hope it'll help.

share|improve this answer
That's not a join, that is a select with a where clause. I am talking about a select from table A inner join table B on A.pkid = B.fkid. Something like this.... – JL01 Apr 11 '11 at 15:18
Found this solution that has some great examples: – JL01 Apr 11 '11 at 18:08
Well it's ok if your lists are small, but you can get performance hit if they are large, beacuse you retreaving all items from both lists and then doing join - not the best way, better think about using lookup field – Andriy Shvay Apr 12 '11 at 6:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.