QueryExpressions Object Initializer Syntax: QueryExpressions are a very powerful way to query data in Dynamics 365. They provide all features of FetchXml queries apart of aggregates and grouping. In contrast to FetchXml queries, they provide a strongly typed object model. To make your queries more readable, I recommend to always make use of object initializer syntax to construct complex queries. Object and collection initializers are c# syntax features, which are available since C# version 3.0 (.net 3.5).
This example shows a query expression, which retrieves all permission roles of a user without using object initializer syntax:
And the same query using object initializer syntax:
Although more lines of code are needed, it makes the query much more reader friendly and you get an immediate understanding of what the query is doing.
Finally: Make sure to use XrmToolBox Latebound Constants Generator to replace all hardcoded string with constants.
Add new comment