web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Dynamics Chronicles / QueryExpressions and Object...

QueryExpressions and Object Initializer Syntax

Dynamics Chronicles Profile Picture Dynamics Chronicles 958
QueryExpressions and Object Initializer Syntax Mattias Liloia Mon, 11/30/2020 - 11:26
Body

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:

without  syntax

And the same query using object initializer syntax:

with 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.

QueryExpressions Object Initializer Syntax


This was originally posted here.

Comments

*This post is locked for comments