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.
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.
