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
||Use this to retrieve all data for an entity. Value = 15.
||Use this to retrieve entity information plus attributes for the entity. Value = 2.
||Use this to retrieve only entity information. Equivalent to EntityFilters.Entity . Value = 1.
||Use this to retrieve only entity information. Equivalent to EntityFilters.Default . Value = 1.
||Use this to retrieve entity information plus privileges for the entity. Value = 4.
||Use 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
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.