我正在使用早期绑定编写联系人实体的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");
}
}
GetRelatedEntity
如何工作? - Guido Preite