In most cases, you should use LINQ to SharePoint, instead of the SPQuery class, to perform data operations on lists. However, there are still some circumstances in which SPQuery is the most appropriate option—or the only option—for data access. Most notably, using the SPQuery class is the only supported server object model approach for programmatically working with data in external lists.

With External List, you need to use SPQuery.


1. Create SPQuery instance
2. Set properties on SPQuery instance
3. Cal the GetItems on SOList instance, passing SPQuery instance as a parameter

LINQ to SharePoint
does not support anonymous user access.

Consider using SPQuery over LINQ to SP when:

1. When you have anonymous users
2. When a lookup column in a list refers to a list in another site withint he site collection. SPQuery allow to join lists from both sites.
3. Whe performance is important.

Sandbox + Splist + External Content Type à No full trust proxy is needed


Use to query data from multiple lists across different site collection. SPSiteDataQuery is commonly used in list aggregation scenario. No Join or porjected field. No external data.

Because of a bug in SharePoint 2010, an SPException (hr=0x80004005) is thrown if you execute an SPSiteDataQuery on a site that contains an external list with a column named Id. This may be fixed in a future service pack or cumulative update.

1. Create SPSiteDataQuery instance
2. Set properties
3. Cal the GetSiteData() on SPWeb, passing SPSiteDataQUery as a parameter. Returns a DataTable.

SPSiteDataQuery best performed in:

  1. Multiple lists in the same site collection.
  2. Query across 2 lists that are not related by lookup columns
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: