We know that LINQ to Sharepoint is actually converted into calm for access to SharePoint. So how can we know what the calm statement we write is eventually converted.
We can use the following methods to achieve our goal.
1. First, create a new class named camldebug in our SharePoint project ,:
Calmdebug. CSCodeAs follows:
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. IO;
Using Microsoft. Sharepoint. LINQ;
NamespaceNorthwindlinqtosp
{
Public ClassCamldebug: idisposable
{
PrivateDatacontext _ context;
Public stringwriter writer
{< br> Get ;
private set ;
}
Public camldebug (datacontext context)
{< br> _ context = context;
writer = New stringwriter ();
_ context. log = writer;
}
Public override string tostring ()
{< br> writer. flush ();
return writer. getstringbuilder (). tostring ();
}
Public VoidDispose ()
{
_ Context. log =Null;
Writer. Dispose ();
}
}
}
2. Then use this class in our LINQ to SharePoint code
VaR Dc = New Northwindentitydatacontext (spcontext. Current. Web. url );
Mycustomers = Dc. getlist <acustomeritem> ("Acustomer");
Myorders = Dc. getlist <aordersitem> ("Aorders");
Using(Camldebug DEBUG =NewCamldebug (DC ))
{
StringQueries = Debug. tostring ();
VaR Query = From C In Mycustomers
Where (From O In Myorders
Select O. bcsfindcustomerid). Contains (C. bcsfindcustomerid)
Select C;
This . Lblmsg2.text = " Items: " + Query. Count (). tostring ();
This. Gvdetails. datasource = query;
This. Gvdetails. databind ();
}
3. Set a breakpoint in the code segment to go to debugging (of course, you can also output the calm string saved by queries to any place you want)
4. Here, some people directly use the following code to output the generated calm directly to the specified TXT file without using the above class for viewing.
VaR Dc = New Northwindentitydatacontext (spcontext. Current. Web. url );
Mycustomers = Dc. getlist <acustomeritem> ( " Acustomer " );
Myorders = Dc. getlist <aordersitem> ( " Aorders " );
Textwriter =NewStreamwriter (@"C: \ caml.txt",False);
DC. log = textwriter;
VaR Query =From C In Mycustomers
Where ! ( From O In Myorders
Select O. bcsfindcustomerid). Contains (C. bcsfindcustomerid)
Select New
{
Copanyname = C. bcsfindcompanyname,
Contanctname = C. bcsfindcontactname,
Address = New
{
Country = C. bcsfindcountry,
City = C. bcsfindcity,
Postalcode = C. bcsfindpostalcode
}
};
This. Lblmsg2.text ="Items:"+ Query. Count (). tostring ();
This. Gvdetails. datasource = query;
This. Gvdetails. databind ();
The output result of the above Code is as follows:
The next task is in yourSpquery
(The following is a reference example for reference only)
Spquery query = New Spquery ();
Query. query = @" <Where>
<And>
<Beginswith>
<Fieldref name = 'contenttypeid'/>
<Value type = 'contenttypeid'> 0x0100 </value>
</Beginswith>
<Beginswith>
<Fieldref name = 'productcontenttypeid'/>
<Value type = 'lookup '> 0x0100 </value>
</Beginswith>
</And>
</Where>
<Orderby override = 'true'/> " ;
Query. viewfields = @" <Fieldref name = 'title'/>
<Fieldref name = 'productproductname '/> " ;
Query. projectedfields = @" <Field name = 'productproductname 'Type = 'lookup'
List = 'apache' showfield = 'productname '/>
<Field name = 'productcontenttypeid' type = 'lookup'
List = 'apache' showfield = 'contenttypeid'/> " ;
Query. Joins = @" <Join type = 'inner 'listalias = 'aproduct'>
<EQ>
<Fieldref name = 'product' reftype = 'id'/>
<Fieldref list = 'product' name = 'id'/>
</EQ>
</Join> " ;
query. rowlimit = 2657495668 ;
var List = web. lists [ "A orders " ];
var items = List. getitems (query);
foreach (splistitem in items)
{< br> This . listboxoutput. items. add (item [ " title " ] + item [" productproductname " ]);
}