我正在使用 crmsvcutil 生成早期绑定类型。在 crm 4.0 天,只需点击 entity.ChildEntities 属性即可加载相关实体。
//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();
}
}
}
当我使用最新的 CRM 2011 SDK 版本而不是加载 realted 实体时,我得到了一个 NullReferenceException ,它没有给我关于这个问题的更多信息。
foreach (var c in a.contact_customer_accounts)
我想念什么?如何使用 CRM2011 Linq 加载相关实体?