I've been converting some of my CRM4.0 plugins to use the CRM2011 SDK. I'm just starting to work with LINQ for Early-Bound entities and have come across a problem.
I am trying to get the formatted value of an OptionSetValue in a joined entity. After looking at this MSDN SDK Query Example, I managed to retrieve the formatted values for the primary entity, but can't seem to translate that to a joined entity.
The code below is a sample of what I'm trying to achieve. I started by using the code from the SDK example.
var query_join8 = (from a in sContext.AccountSet
join c in sContext.ContactSet
on a.PrimaryContactId.Id equals c.ContactId
into gr
from c_joined in gr.DefaultIfEmpty()
select new
{
contact_name = c_joined.FullName,
account_name = a.Name,
account_addresstypecode = a.Address1_AddressTypeCode,
account_addresstypename = a.FormattedValues.ContainsKey("address1_addresstypecode") ? a.FormattedValues["address1_addresstypecode"] : null,
account_formattedValues = a.FormattedValues,
contact_addresstypecode = c_joined.Address1_AddressTypeCode,
contact_addresstypename = c_joined.FormattedValues.ContainsKey("address1_addresstypecode") ? c_joined.FormattedValues["address1_addresstypecode"] : null,
contact_formattedValues = c_joined.FormattedValues,
}).ToArray();
The account_formattedValues and account_addresstypename come across corrected and I have access to that data, but for some reason the contact_formattedValues item contains an empty collection, and thus contact_addresstypename is null.
Am I doing this incorrectly, or have I missed something? Has anyone been able or knows how to achieve this? Any help is greatly appreciated.