In CAML, it is possible to perform such joins INNER LEFT or type. The difference between these two types of joints is very important. We see this in the explanation of our example. Come back to your class and add the following directive:
Code:
using Microsoft . SharePoint ;
Then state the following function:
Code:
private void AfficherMonumentEtVille ( string type) { }
The purpose of this function will display all the monuments as well as information about their city and their country. The type parameter will allow to define whether the join type is INNER or LEFT and allow us to understand the difference. The first thing to do in this function is to retrieve a reference to the list and create an object SPQuery to perform the query:
Code:
SPList list = SPContext . Current . Web . Lists [ " Monuments " ] ; SPQuery query = new SPQuery () ;
We will base ourselves on the list because they are monuments to the information of monuments and information related to this monument that we want to retrieve. We will now define the property Join the petition. It is in this property, we will define the format of the join. We will directly display the code Join and we will explain below:
Code:
query . Joins = string . Format ( " <Join Type='{0}' ListAlias='VillesList'> " + " <Eq> " + " <FieldRef Name='Ville' RefType='Id' /> " + " <FieldRef List='VillesList' Name='ID' /> " + " </Eq> " + " </Join> " , type) ;
As we have said, the property will allow Join contain code showing how CAML or the joints will be performed. Here, for starters, we will make a single joint. Basically, we will join the table to table Monuments Cities City field through the table monument. Thus, we will recover the information of each monument as well as information about the city in which these monuments are located.
Bookmarks