2

I am unable to create a working query with join in my .net csom application. I was using this article:

http://msdn.microsoft.com/en-us/library/ff798388.aspx

here is my code:

 ClientContext context = new ClientContext(url);
 Web web = context.Web;
 var list = web.Lists.GetByTitle("Esemény");

 CamlQuery cq = new CamlQuery();
 cq.ViewXml= @"<View>
                   <ViewFields>
                       <FieldRef Name='Title' />
                   </ViewFields>
                   <ProjectedFields>
                       <Field Name='PartnerLookupTitle' Type='Lookup' List='PartnerLookup' ShowField='Title' />
                   </ProjectedFields>
                   <Joins>
                       <Join Type='LEFT' ListAlias='PartnerLookup'>
                           <Eq>
                               <FieldRef Name='Partner' RefType='ID' />
                               <FieldRef List='Partner' Name='ID' />
                           </Eq>
                       </Join>
                   </Joins>
               </View>";

ListItemCollection lista =  list.GetItems(cq);
context.Load(lista);
context.ExecuteQuery();

I get an exception from the server: "Value does not fall within the expected range."

If I remove the the ProjectedFields and Joins part of the CAML query it works:(


Ok. I could create a working query:

                @"<View>

                    <ViewFields>
                      <FieldRef Name='Title' />
                      <FieldRef Name='Partner'/>
                      <FieldRef Name='PartnerLookupTitle'/> //new code
                    </ViewFields>

                    <ProjectedFields>
                        <Field Name='PartnerLookupTitle' Type='Lookup' List='PartnerLookup' ShowField='Title' />
                    </ProjectedFields>
                    <Joins>
                      <Join Type='LEFT' ListAlias='PartnerLookup'>
                        <Eq>
                          <FieldRef Name='Partner' RefType='ID' />
                          <FieldRef List='PartnerLookup' Name='ID' />
                        </Eq>
                      </Join>
                    </Joins>

                  </View>";

Now I can acces the PartnerLookupTitle field, but still dont get this line of code:

<FieldRef List='PartnerLookup' Name='ID' />

1 Answer 1

4

I think your definition for the join is wrong. I think it should be:

<Join Type='LEFT' ListAlias='PartnerLookup'>
  <Eq>
    <FieldRef Name='Partner' RefType='ID' />
    <FieldRef List='PartnerLookup' Name='ID' />
  </Eq>
</Join>
1
  • Thank you for the answer. I tryed to modify my code as you suggested and now it works. I dont get an Exception on ExecuteQuery anymore. Can you please explain me, why should I write PartnerLookup instead Partner. I'm afraid I dont understand. I have 2 Lists, called Esemény and Partner the Esemény list has one lookup field called (also) Partner referring the Partner List. And now when I'm trying to acces the "PartnerLookupTitle" Console.WriteLine(listItem["PartnerLookupTitle"]; I get the Exception: PartnerOrFieldNotInitializedException Commented Sep 19, 2013 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.