Getting entity type code via metadata service
an Example for CRM 4.0
string entityTypeName = "contact";
RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest();
request.MetadataItems = MetadataItems.EntitiesOnly;
RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)metadataService.Execute(request);
CrmMetadata[] Metadata = response.CrmMetadata;
foreach (EntityMetadata meta in Metadata) {
if (meta.LogicalName == entityTypeName)
return meta.LogicalName;
}
Enjoy,
Rami Heleg