Export (0) Print
Expand All

Using the ColumnSet Class

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

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.

Example

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

[C#]
// 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

Reference

Other Resources


© 2010 Microsoft Corporation. All rights reserved.


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft