Using the SharePoint 2010 Managed Client Object Model – Increasing Performance by Nesting Includes in LoadQuery

This is a clipboard friendly version of example #9, Increasing Performance by Nesting Includes in LoadQuery, from Using the SharePoint 2010 Managed Client Object Model.

This blog is inactive.
New blog: EricWhite.com/blog

Blog TOC

using System;
using System.Collections.Generic;
using Microsoft.SharePoint.Client;

class Program
{
static void Main()
{
ClientContext clientContext =
new ClientContext("https://intranet.contoso.com");
IEnumerable<List> lists = clientContext.LoadQuery(
clientContext.Web.Lists.Include(
list => list.Title,
list => list.Hidden,
list => list.Fields.Include(
field => field.Title,
field => field.Hidden)));
clientContext.ExecuteQuery();
foreach (List list in lists)
{
Console.WriteLine("{0}List: {1}",
list.Hidden ? "Hidden " : "", list.Title);
foreach (Field field in list.Fields)
Console.WriteLine(" {0}Field: {1}",
field.Hidden ? "Hidden " : "",
field.Title);
}
}
}

Following is the same example using fully qualified names for better discoverability.

using System;
using System.Collections.Generic;
using Microsoft.SharePoint.Client;

class Program
{
static void Main()
{
Microsoft.SharePoint.Client.ClientContext clientContext =
new Microsoft.SharePoint.Client.ClientContext("https://intranet.contoso.com");
IEnumerable<Microsoft.SharePoint.Client.List> lists = clientContext.LoadQuery(
clientContext.Web.Lists.Include(
list => list.Title,
list => list.Hidden,
list => list.Fields.Include(
field => field.Title,
field => field.Hidden)));
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.List list in lists)
{
Console.WriteLine("{0}List: {1}",
list.Hidden ? "Hidden " : "", list.Title);
foreach (Microsoft.SharePoint.Client.Field field in list.Fields)
Console.WriteLine(" {0}Field: {1}",
field.Hidden ? "Hidden " : "",
field.Title);
}
}
}