4

Trying to migrate an existing solution away from the deprecated Microsoft.Xrm.Client namespace to just use the generated service context from CrmSvcUtil using CrmSDK 9.0.0.5.

Previously we were using Microsoft.Xrm.Client.CodeGeneration.CodeCustomization to get a lazily loaded context.

I have two copies of the same solution and have been working through some of the API changes.

I have enabled Proxy Types

client.OrganizationServiceProxy.EnableProxyTypes();

Which to my understanding switched it to act in a lazily-loaded manner. However, none of the navigation properties are loading as expected.

The few blog posts that I've found around this shift to CrmServiceClient etc suggest that even without lazy loading I should be able to load the property manually with a call to Entity.LoadProperty() which will either load the property or refresh the data. However, after doing that the navigation property is still null (specifically I'm trying to use a Contact navigation property). When I look through the RelatedEntities collection it is also empty.

I know that the entity has a related contact item as if I use a context generated with Microsoft.Xrm.Client.CodeGeneration.CodeCustomization it returns it and I can also see it in CRM itself using an advanced search.

var connectionUri = ConfigurationManager.ConnectionStrings["Xrm"].ConnectionString;
var client = new CrmServiceClient(connectionUri);
client.OrganizationServiceProxy.EnableProxyTypes();
var context = new XrmServiceContext(client);

var result = context.new_applicationSet.FirstOrDefault(x => x.new_applicantid.Id == CurrentUserId);
//result.Contact is null
context.LoadProperty(result, "Contact");
//result.Contact is still null
//result.RelatedEntities is empty
Technicolour
  • 677
  • 1
  • 7
  • 17
  • I checked you code on my instance and it works without a problem. I'm using the latest XrmTooling and the latest Xrm.SDK (both 9.0.0.7). Maybe try to update the version of your SDK? Also I don't know if that is a problem with your example but in your code you are selecting all the attributes of new_application entity. Therefore all existing values will be already there so LoadProperty will not change anything in this case - if it's null in the first place, it will be null after the call – Pawel Gradecki Dec 08 '17 at 07:58
  • And you don't need to do `client.OrganizationServiceProxy.EnableProxyTypes()` Xrm.Tooling does this for you by default. – Pawel Gradecki Dec 08 '17 at 07:59

0 Answers0