我正在使用早期绑定在联系人实体上编写 PostUpdate 插件。
不幸的是,所有应该表示 1:x 关系的属性都是空的。
代码非常简单:
* CRMcontext 是通过 CrmSvcUtil.exe 生成的文件,
* service 是 LocalPluginContext 中的 IOrganizationService:
using ( var serviceContext = new CRMcontext(service) )
{
// This works fine
var contact = serviceContext.CreateQuery<Contact>().First(c => c.Id == context.PrimaryEntityId);
// why is currency null after this line?! (and yes, it's set in the entity)
var currency = contact.transactioncurrency_contact;
}
我按照这个例子(最后一个代码片段):http: //msdn.microsoft.com/en-us/library/gg695791.aspx
谢谢你的帮助!
编辑:
/// <summary>
/// N:1 transactioncurrency_contact
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("transactioncurrencyid")]
[Microsoft.Xrm.Sdk.RelationshipSchemaNameAttribute("transactioncurrency_contact")]
public TransactionCurrency transactioncurrency_contact
{
get
{
return this.GetRelatedEntity<TransactionCurrency>("transactioncurrency_contact", null);
}
set
{
this.OnPropertyChanging("transactioncurrency_contact");
this.SetRelatedEntity<TransactionCurrency>("transactioncurrency_contact", null, value);
this.OnPropertyChanged("transactioncurrency_contact");
}
}