Here is sample code
private string GetAttributeSchemaName(IOrganizationService _Service, string
attributeDisplyName)
{
string
attributeSchemaName = null;
try
{
RetrieveEntityRequest req = new RetrieveEntityRequest();
req.RetrieveAsIfPublished = true;
req.LogicalName = "opportunityproduct";
req.EntityFilters = EntityFilters.Attributes;
RetrieveEntityResponse resp = (RetrieveEntityResponse)_Service.Execute(req);
for (int a = 0; a <
resp.EntityMetadata.Attributes.Length; a++)
{
if
(resp.EntityMetadata.Attributes[a].DisplayName.UserLocalizedLabel != null)
{
if
(resp.EntityMetadata.Attributes[a].DisplayName.UserLocalizedLabel.Label.ToLower()
== attributeDisplyName.ToLower())
{
attributeSchemaName =
resp.EntityMetadata.Attributes[a].LogicalName;
break;
}
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
return
attributeSchemaName;
}