I’m using crmsvcutil to generate early bound types. In the crm 4.0 days one was able to load related entites just by hitting the entity.ChildEntities property.
//Winvs.Next.Entities.CrmDataContext dc = new Entities.CrmDataContext(new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(
var cred = new System.ServiceModel.Description.ClientCredentials();
cred.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
//
using (var organizationServiceProxy = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(new Uri(System.Configuration.ConfigurationManager.ConnectionStrings["CrmConnection"].ConnectionString), null, cred, null))
using (Winvs.Next.Entities.CrmDataContext dc = new Entities.CrmDataContext(organizationServiceProxy))
{
// This statement is required to enable early-bound type support.
organizationServiceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new Microsoft.Xrm.Sdk.Client.ProxyTypesBehavior());
//
foreach (var a in dc.AccountSet)
{
foreach (var c in a.contact_customer_accounts)
{
c.FullName.ToString();
}
}
}
When I do this with the latest CRM 2011 SDK version instead of loading realted entities I’m getting a NullReferenceException which gives me no further information about the issue.
foreach (var c in a.contact_customer_accounts)
What Do i miss? How can I load related entities with CRM2011 Linq?
I really have no clue why this is the way it is but it turned out after some researching sessions that one has to use the xrm provided code customization assembly to generate the entity object model classes.
There is a SDK Version 5.0.4 sample provided which builds a sample console showing off how to generate and consume the entity classes in a way we’re all used from the CRM 4.0 xrm days.
To make a long story short I post the crmsvcutil call here, for further information you should consult the sdk sample Walkthrough: Build a Console Application That Connects to Microsoft Dynamics CRM 2011 Using Developer Extensions http://technet.microsoft.com/en-us/library/gg695803.aspx