cub-e.net

just coding...

Dynamics 365 UK Community Event in London on 26th-27th January 2018

Dynamics 365 Saturday is a free Technical & Strategy Event Organised by the Microsoft Dynamics Community MVP’s For CRM and ERP professionals, technical consultants & developers. Learn & share new skills whilst promoting best practices, helping organisations overcome the challenges of implementing a successful digital transformation strategy with Microsoft Dynamics 365.

Dynamics 365 Saturday will replace CRM Saturday to provide a single platform to serve the whole Dynamics 365 community, the core customer experience values and ethics of CRM Saturday will continue to live on through 365 Saturday with the rest of the Dynamics Community.

I and Ramon Tebar (Investec CRM Solution Architect) will share their knowledge on Dynamics 365 in Hackathon on 26th January also they have a session in this event on 27th January. Session name is “Dynamics 365 V9 New Features & Deprecations” in Theatre 1 between 10:00 and 11:00.

Their session focuses on who interested in taking the plunge to “code”. The session will be covering all development structure. Attendees can easily see the difference between versions from a development perspective and will be particularly helpful for those who work on upgrade projects.

Avoid selecting all columns via Microsoft Dynamics CRM query APIs

For optimal performance, you should only select the minimum amount of data needed by your application when querying CRM data.  Queries that include a defined ColumnSet where the ColumnSet.AllColumns property is 'true' instruct the CRM data access platform to issue a SELECT * on all physical data included in the query plan.  This scenario should be avoided whenever possible.  
 

Violation Examples

ColumnSet.AllColumns setter method call

    var columns = new ColumnSet();

    columns.AllColumns = true;

 

    var query = new QueryExpression("account");

    query.ColumnSet = columns;

 

    var results = service.RetrieveMultiple(query);

ColumnSet(bool allColumns) constructor overload

    var query = new QueryExpression("account")

    {

        ColumnSet = new ColumnSet(true)

    };

 

    var results = service.RetrieveMultiple(query);

ColumnSet(bool allColumns) constructor overload for RetrieveRequest

    var entity = service.Retrieve("account"Guid.NewGuid(), new ColumnSet(true));


Guideline Examples 

 

ColumnSet(param string[] columns) constructor overload for QueryExpression

    var query = new QueryExpression("account")

    {

        ColumnSet = new ColumnSet("name""address1_city")

    };

 

    var results = service.RetrieveMultiple(query);

ColumnSet(param string[] columns) constructor overload for RetrieveRequest

    var entity = service.Retrieve("account"Guid.NewGuid(), new ColumnSet("name""address1_city"));

ColumnSet.AddColumn(string column) method call

    var query = new QueryExpression("account");

    query.ColumnSet.AddColumn("name");

    query.ColumnSet.AddColumn("address1_city");

 

    var results = service.RetrieveMultiple(query);

ColumnSet.AddColumns(param string[] columns) method call

    var query = new QueryExpression("account");

    query.ColumnSet.AddColumns("name""address1_city");

 

    var results = service.RetrieveMultiple(query);


Usage of the Retrieve method should set the columnSet parameter to a ColumnSet instance with specified columns.  Usage of QueryExpression should set the  QueryBase.ColumnSet property with the required attributes. 

The following messages contain reference a ColumnSet instance:

Message

ConvertQuoteToSalesOrderRequest Class 

ConvertSalesOrderToInvoiceRequest Class 

GenerateInvoiceFromOpportunityRequest Class 

GenerateQuoteFromOpportunityRequest Class 

GenerateSalesOrderFromOpportunityRequest Class 

QueryByAttribute Class 

QueryExpression Class 

RetrieveAllChildUsersSystemUserRequest Class 

RetrieveBusinessHierarchyBusinessUnitRequest Class 

RetrieveMembersTeamRequest Class 

RetrieveRequest Class 

RetrieveSubsidiaryTeamsBusinessUnitRequest Class 

RetrieveSubsidiaryUsersBusinessUnitRequest Class 

RetrieveTeamsSystemUserRequest Class 

RetrieveUnpublishedRequest Class 

RetrieveUserSettingsSystemUserRequest Class 

ReviseQuoteRequest Class 

SearchByBodyKbArticleRequest Class

 

Build queries with QueryExpression

In Microsoft Dynamics 365 (online & on-premises), you can use the QueryExpression class to programmatically build a query containing data filters and search conditions that define the scope of a database search. A query expression is used for single-object searches. For example, you can create a search to return all accounts that match certain search criteria. The QueryBase class is the base class for query expressions. There are two derived classes: QueryExpression and QueryByAttribute. The QueryExpression class supports complex queries. The QueryByAttribute class is a simple means to search for entities where attributes match specified values.

Query expressions are used in methods that retrieve more than one record, such as the IOrganizationService.RetrieveMultiple method, in messages that perform an operation on a result set specified by a query expression, such as BulkDeleteRequest and when the ID for a specific record is not known.

In addition, there is a new attribute on the organization entity, Organization.QuickFindRecordLimitEnabled. When this Boolean attribute is true, a limit is imposed on quick find queries. If a user provides search criteria in quick find that is not selective enough, the system detects this and stops the search. This supports a faster form of quick find and can make a big performance difference.


References:  

Use the QueryExpression Class

http://msdn.microsoft.com/en-us/library/gg334688.aspx

ColumnSet Class

http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.query.columnset.aspx

Use of the ColumnSet Class

http://msdn.microsoft.com/en-us/library/gg309532.aspx