I am writing an app which uses XRM SDK to get data from MS CRM 11. For fields of type lookup I want to get their corresponding definition so I can retrieve all possible ids and values from the related entity.
I cannot seem to find a way to get this. I understand I can get the entity reference for an entity instance value and how to get target entities from meta data but cannot find anything to help me get all lookup ids and values for a lookup field. Please help!
Edit:
In the interest of helping others, and after several more days investigation, I am convinced what I want to do is not possible server-side using sdk.
I can get pick list values no problem using a RetrieveAttributeRequest and cast the resulting AttributeMetaData to PicklistAttributeMetadata. You can use the same technique to deal with Lookups by casting to LookupAttributeMetadata but this only gives you one useful property over the base class: Targets. All this does is provide a string array of entity logical names. It gives you no additional detail such as mapped Id/Name properties or any view details for lookups where queries are applied (such as primary contact lookups where contacts listed are for current organisation).
So, in the end I have had to compromise. I can get the target entity name from Targets and assume that the lookup is simple - just pull all records from entity. The Id column is fixed so that is ok and generally you are safe to assume the Name column is available (albeit likely asl_name etc. if custom).
If anyone knows a better way I will gladly, willingly eat humble pie!