Hello World,
When
you get to a scenario where you are writing a generic logic to be shared in few
plugin steps and you are not sure about the entity you will get to process, but
you need to know the schema names of primary field and id of the given entity.
So pathetic right :)
Here
is my solution. Use metadata.
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
//Create RetrieveEntityRequest
RetrieveEntityRequest retrievesEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Entity,
LogicalName = primaryEntityName
};
//Execute Request
RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse) service.Execute(retrievesEntityRequest);
var idFieldName = retrieveEntityResponse.EntityMetadata.PrimaryIdAttribute;
var primaryFieldName = retrieveEntityResponse.EntityMetadata.PrimaryNameAttribute;
Need
to discuss about getting entity relationships too. Next post for sure.
No comments:
Post a Comment