DEVKIT1002 - phuocle/Dynamics-Crm-DevKit GitHub Wiki
This analyzer warns against using ColumnSet(true) or AllColumns = true which retrieves all columns from an entity. This is a well-known performance anti-pattern that retrieves unnecessary data and increases memory consumption.
📚 Retrieve specific columns for a table via query APIs
When you submit queries to retrieve data, include specific columns in the ColumnSet instance. Retrieving all columns causes performance issues.
Using ColumnSet(true) has several negative impacts:
- Performance Degradation: Retrieves ALL columns, including large text fields, file columns, and calculated fields
- Increased Memory Usage: More data transferred means higher memory consumption
- Network Overhead: Larger payloads increase network latency
- Database Load: Forces unnecessary column reads from the database
| Pattern | Description |
|---|---|
new ColumnSet(true) |
Constructor with true parameter |
AllColumns = true |
Property assignment |
<all-attributes/> |
FetchXML all-attributes element |
The analyzer flags usages where:
-
new ColumnSet(true)is called -
ColumnSet.AllColumnsproperty is set totrue
// ColumnSet constructor with true
var entity = service.Retrieve("account", accountId, new ColumnSet(true));
// AllColumns property set to true
var query = new QueryExpression("account")
{
ColumnSet = new ColumnSet { AllColumns = true }
};
var results = service.RetrieveMultiple(query);// Only retrieve the columns you need
var entity = service.Retrieve("account", accountId,
new ColumnSet("name", "accountnumber", "primarycontactid"));
// Explicit column list in QueryExpression
var query = new QueryExpression("account")
{
ColumnSet = new ColumnSet("name", "accountnumber", "emailaddress1")
};
var results = service.RetrieveMultiple(query);- Identify Required Columns: Determine which columns your code actually uses
-
Replace with Specific Columns: Change
ColumnSet(true)toColumnSet("column1", "column2", ...) -
Review FetchXML: Replace
<all-attributes/>with individual<attribute name='...'/>elements
- var account = service.Retrieve("account", id, new ColumnSet(true));
+ var account = service.Retrieve("account", id, new ColumnSet("name", "accountnumber"));If you have a legitimate need to suppress this warning:
#pragma warning disable DEVKIT1002
var entity = service.Retrieve("account", id, new ColumnSet(true));
#pragma warning restore DEVKIT1002Or in .editorconfig:
[*.cs]
dotnet_diagnostic.DEVKIT1002.severity = suggestion| Property | Value |
|---|---|
| Rule ID | DEVKIT1002 |
| Category | DynamicsCrm.DevKit |
| Severity | Warning |
| Enabled by default | Yes |