Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

I have used SPMetal to generate entity.cs based on this article: http://www.eggheadcafe.com/tutorials/aspnet/b0c1cd0d-fe82-444e-a16e-7d3fb7d38eca/join-lists-with-linq--sh.aspx

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?

UPDATE:

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
add comment

1 Answer

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: solutionizing.net/2009/04/30/join-sharepoint-lists-with-linq –  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
add comment

Your Answer

 
discard

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.