Using the ColumnSet Class

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

The ColumnSet class is used to specify which attributes are to be retrieved in the results of a query. To reduce the data that is passed from the server to the client, the default column set returns only the primary key.

To retrieve all columns, pass a new instance of the AllColumns class. However, notice that retrieving all the attributes for an entity will affect the performance of your code.

Warning   You should avoid using AllColumns in a query expression because of the impact on a subsequent update of records. In an update, this will set all field values, even if they are unchanged, and often triggers cascaded updates to child records.


The following example shows how to use a column set to return only two attributes from the account entity.

// Create a column set holding the names of the columns to be retrieved.
ColumnSet cols = new ColumnSet();
cols.Attributes = new string [] {"name", "accountid"};
 [Visual Basic .NET]
' Create a column set holding the names of the columns to be retrieved.
Dim cols As New ColumnSet()
cols.Attributes = New String() {"name", "accountid"}

The following example shows how to use the AllColumns class to return all columns from the account entity.

[Visual Basic .NET]
' Create the query object.
Dim query As New QueryByAttribute()

' Be aware that using AllColumns may adversely affect 
' performance and cause unwanted cascading in subsequent 
' updates.  A best practice is to retrieve the least amount of 
' data required.
query.ColumnSet = New AllColumns()
query.EntityName = EntityName.account.ToString()

See Also


Other Resources

© 2010 Microsoft Corporation. All rights reserved.