Recently, I had been having a CRM issue. I needed to retrieve the CreatedBy attribute for a customer CDH entity, so I could compare it to the current user for some approval business logic.
I attempted the usual in LINQ:
But, no matter what I did, the field was always null (even though the values returned in LINQPad fine). Then, I discovered that for certain attributes that represent associations or links, CRM does not load the values by default.
The missing piece is to manually call the LoadProperty on the OrganizationServiceContext, and then the attribute is populated.
This was quite difficult to figure out, so I hope this saves someone else some time troubleshooting!
Here is the link to the LoadProperty Function:
Written By Shawn Strayer, Web Developer at Rockton Software www.rocktonsoftware.com.