I have an issue where if I query for an Opportunity after it was used in a join in a linq statement, the Opportunity is always returned with no data. Here is an example:
var matchingActivities =
(from a in _context.CreateQuery(activityType)
join o in _context.CreateQuery<Opportunity>() on ((EntityReference)a["regardingobjectid"]).Id equals o.OpportunityId
where
(o.ContactId.Id == stakeholder || o.glh_SecondaryContact.Id == stakeholder) &&
o.glh_SalesOffice.Id == salesOfficeId &&
a.GetAttributeValue<DateTime?>("actualstart") >= startDate
select a).ToList();
If I subsequently query the same opportunity that was used in the join, its field are always blank.
var opportunity = _context.CreateQuery<Opportunity>().FirstOrDefault(o => o.Id == opportunityId);
I have been banging my head against the wall for hours to try and figure this out. Any help would be greatly appreciated.