Use the ColumnSet class

In Microsoft Dataverse, you can use the ColumnSet class to specify what columns (attributes) to return from a query defined using the QueryExpression and QueryByAttribute classes. It is also a parameter for the IOrganizationService.Retrieve method and it is used as a property in a number of message request classes which return data in an EntityCollection.

Note

The ColumnSet class has an AllColumns property which specifies that all columns of the table should be returned. As a performance best practice, you should not use this for production code. More information: Do not retrieve Entity all columns via query APIs

The following code example shows how to use the ColumnSet class to specify what columns to return from a query expression.

QueryExpression contactquery = new QueryExpression   
{  
   EntityName="contact",  
   ColumnSet = new ColumnSet("firstname", "lastname", "contactid")   
};  

See also

Using the QueryExpression Class
Building Queries with QueryExpression
Use the ConditionExpression Class
QueryExpression class
QueryByAttribute class