Fixed – The given key was not present in the dictionary error while using FormattedValues in LINQ in CRM 2013.
Hi,
I was getting the following exception while trying to get the text for an option set field named area of law in linq.

The query with joins
var authorization = (from a in
SDKHelper.XrmServiceContext.lss_AuthorizationSet join c in SDKHelper.XrmServiceContext.lss_contractSet on a.lss_ContractId.Id equals c.Id
join l in
SDKHelper.XrmServiceContext.lss_lawyerSet on c.lss_LawyerId.Id equals l.Id
where a.lss_AuthID == authorizationId
select
new
Authorization{
AreaOfLawAndContractType = c.lss_Area_of_Law != null? c.FormattedValues[“lss_area_of_law”] : default(string)
}).FirstOrDefault();
return authorization;
The fix was instead of using FormattedValues collection of related entity in join, we need to use the FormattedValues collection of the primary entity.
var authorization = (from a in
SDKHelper.XrmServiceContext.lss_AuthorizationSet
join c in
SDKHelper.XrmServiceContext.lss_contractSet on a.lss_ContractId.Id equals c.Id
join l in
SDKHelper.XrmServiceContext.lss_lawyerSet on c.lss_LawyerId.Id equals l.Id
where a.lss_AuthID == authorizationId
select
new
Authorization
{
AreaOfLawAndContractType = c.lss_Area_of_Law != null? a.FormattedValues[“lss_area_of_law”] : default(string)
}).FirstOrDefault();
return authorization;
Hope it helps.
Filed under: CRM, CRM 2013, Microsoft Dynamics CRM Tagged: CRM 2013, Microsoft Dynamics CRM
This was originally posted here.

Like
Report
*This post is locked for comments