如何使用RelatedEntities集合创建RelatedEntities(How To Use The RelatedEntities Collection To Create RelatedEn

系统教程 行业动态 更新时间:2024-06-14 16:59:47
如何使用RelatedEntities集合创建RelatedEntities(How To Use The RelatedEntities Collection To Create RelatedEntities)

我试图遵循这里描述的逻辑: 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.

更多推荐

本文发布于:2023-04-17 09:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/b39672ac58f5f7be3eee372549dffc34.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   RelatedEntities   Create   Collection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!