Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Seems to be a common problem. For the answer, I'm looking for the most efficient way to call a secondary list, based on values in a primary list.

I have a list of Posts, and a list of Comments. Each comment has a field called ItemID.

Whenever I load a set of posts, I need to get all the comments for those posts. Sometimes, this could be as many as 200 posts, resulting in 1000 or more comments.

Theoretically, I could build a CAML search statement from the ID's of all posts, like this:

foreach(SPListItem item in returnedList)
{
  string CAML += string.Format("<Or><Eq><FieldRef Name=\"ItemID\" /><Value Type=\"Number\">{0}</Value></Eq></Or>",item.ID.ToString())
}//Just an example, not 100% accurate

I could also use a Join Statement in my Query.

I'm not great with SharePoint Join. It seems like this might be superior because I'm doing one call instead of two. Which method is superior? If I call both lists with a Join, do I get two SPListItemCollections, or are they returned together?

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.