我试图遵循这里描述的逻辑: https : //msdn.microsoft.com/en-us/library/gg309282.aspx,用于使用RelatedEntities属性创建关联实体。 问题是,没有相关实体被创建。 我试图在Pre = Operation插件中执行此操作... PreOperation插件中是否不支持它? 如果是,我做错了什么?
这是代码:
var collection = new EntityCollection(); collection.Entities.AddRange(incentives.Select(e => e.ToSdkEntity())); target.RelatedEntities.Add(new Relationship(new_LeadProduct.Fields.new_lead_new_leadproduct_LeadId), collection);I'm attempting to follow the logic describe here: https://msdn.microsoft.com/en-us/library/gg309282.aspx for creating associated entities using the RelatedEntities Property. Problem is, no Associated Entities are getting created. I'm attempting to perform this action from within a Pre=Operation plugin... Is it not supported within a PreOperation Plugin? What am I doing wrong if it?
Here is the code:
var collection = new EntityCollection(); collection.Entities.AddRange(incentives.Select(e => e.ToSdkEntity())); target.RelatedEntities.Add(new Relationship(new_LeadProduct.Fields.new_lead_new_leadproduct_LeadId), collection);最满意答案
由于预创建插件在数据库中创建目标实体之前执行,因此您将无法创建引用目标的相关实体。 您应该在后创建插件中执行相关的实体逻辑。
编辑:如果您尝试在插件操作中创建与目标关联的相关记录,则此答案适用。 您的问题没有另行说明,但根据您的答案中的代码,看起来这不是您想要做的。
Here is the code from the MSDN Example:
//Define the account for which we will add letters Account accountToCreate = new Account { Name = "Example Account" }; //Define the IDs of the related letters we will create _letterIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; //This acts as a container for each letter we create. Note that we haven't //define the relationship between the letter and account yet. EntityCollection relatedLettersToCreate = new EntityCollection { EntityName = Letter.EntityLogicalName, Entities = { new Letter{Subject = "Letter 1", ActivityId = _letterIds[0]}, new Letter{Subject = "Letter 2", ActivityId = _letterIds[1]}, new Letter{Subject = "Letter 3", ActivityId = _letterIds[2]} } }; //Creates the reference between which relationship between Letter and //Account we would like to use. Relationship letterRelationship = new Relationship("Account_Letters"); //Adds the letters to the account under the specified relationship accountToCreate.RelatedEntities.Add(letterRelationship, relatedLettersToCreate); //Passes the Account (which contains the letters) _accountId = _service.Create(accountToCreate);After some additional testing, the Related Entities Collection must be populated before the PreOperation stage. So registering this to run on PreValidation works as expected.
更多推荐
发布评论