Quantcast
Channel: Microsoft Dynamics CRM
Viewing all articles
Browse latest Browse all 123975

Blog Post: CRM 2011 Metadata Query Enhancements

$
0
0

Rollup 12 (CRM December 2012 Service Update),  is full of nice new features but a huge bonus was the new capabilities to interact with CRM metadata in a much more efficient manner along with benefiting from improved performance. Only retrieving the metadata that you only require and need is a much more pleasing idea especially when it comes to mobile clients.  The MSDN SDK article can be found here that covers this subject in more detail. http://msdn.microsoft.com/en-us/library/jj863599.aspx

The following classes offer this new functionality

Prior to Rollup 12 you could use RetrieveEntityRequest or RetrieveAllEntitiesRequest in the Microsoft.Xrm.Sdk.Messages namespace but were limited to the amount of query filters so when you queried for entity data you essentially received more than sometimes necessary. You can see the EntityFilters enumeration here http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.metadata.entityfilters.aspx

FiltersDescription
AllUse this to retrieve all data for an entity. Value = 15.
AttributesUse this to retrieve entity information plus attributes for the entity. Value = 2.
DefaultUse this to retrieve only entity information. Equivalent to EntityFilters.Entity . Value = 1.
EntityUse this to retrieve only entity information. Equivalent to EntityFilters.Default . Value = 1.
PrivilegesUse this to retrieve entity information plus privileges for the entity. Value = 4.
RelationshipsUse this to retrieve entity information plus entity relationships for the entity. Value = 8.

RetrieveEntityRequest retrieveRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Entity,
LogicalName = _customEntityName
};
RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse)orgService.Execute(retrieveRequest);

As you can imagine if you only want to check if an entity has Is Visible in Mobile flag set then you don’t want anything else. In this case the new EntityQueryExpression class provides a similar experience to the existing QueryExpression for querying CRM  data though specifically for querying metadata.

New metadata query classes include

ClassDescription
AttributeQueryExpressionDefines a complex query to retrieve attribute metadata for entities retrieved using an EntityQueryExpression
DeletedMetadataCollectionThe structure used to return deleted metadata.
EntityQueryExpressionDefines a complex query to retrieve entity metadata.
LabelQueryExpressionDefines the languages for the labels to be retrieved for metadata items that have labels.
MetadataConditionExpressionContains a condition expression used to filter the results of the metadata query.
MetadataFilterExpressionSpecifies complex condition and logical filter expressions used for filtering the results of a metadata query.
MetadataPropertiesExpressionSpecifies the properties for which non-null values are returned from a query.
MetadataQueryBaseRepresents the abstract base class for constructing a metadata query.
MetadataQueryExpressionRepresents the abstract base class for constructing a metadata query.
RelationshipQueryExpressionDefines a complex query to retrieve entity relationship metadata for entities retrieved using an EntityQueryExpression

So to slightly different but if you want to retrieve all entities that have the Is Visible in Mobile set to true using the new classes then specify a filter as follows and execute the RetrieveMetadataChangesRequest message with ClientVersionStamp set to null in the request.

MetadataFilterExpression entityFilter = new MetadataFilterExpression(LogicalOperator.And);
EntityFilter.Conditions.Add(new MetadataConditionExpression("IsVisibleInMobile", MetadataConditionOperator.Equals, true);
EntityQueryExpression entityQueryExpression = new EntityQueryExpression()
{
Criteria = entityFilter
};
RetrieveMetadataChangesRequest retrieveMetadataChangesRequest = new RetrieveMetadataChangesRequest()
{
Query = entityQueryExpression,
ClientVersionStamp = null
};
RetrieveMetadataChangesResponse response = (RetrieveMetadataChangesResponse)orgService.Execute(retrieveMetadataChangesRequest);

The ClientVersionStamp timestamp value representing when the last request was made can be set to only retrieve data that has changed since the time specified.  The RetrieveMetadataChangesResponse returns a timestamp value that can be used with another request at a later time to return information about how metadata has changed since the last request.

This article only scratches the surface of this awesome and long awaited feature so if you want to come up to speed have a read over the SDK article Retrieve and Detect Changes to Metadata.


Filed under: Information, MS CRM, MS CRM 2011 Tagged: ClientVersionStamp, CRM 2011, EntityQueryExpression, Metadata, Microsoft Dynamics CRM 2011, Microsoft.Xrm.Sdk.Metadata.Query, MSCRM, MSCRM 2011, Query, RetrieveAllEntitiesRequest, RetrieveEntity, RetrieveMetadataChangesRequest, RetrieveMetadataChangesResponse, Rollup 12, SDK

Viewing all articles
Browse latest Browse all 123975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>