web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / Fixed – The given key was n...

Fixed – The given key was not present in the dictionary error while using FormattedValues in LINQ in CRM 2013.

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

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.

Comments

*This post is locked for comments