简体   繁体   English

从相交实体 D365 C# 获取相关实体

[英]Getting related entities from intersect entity D365 C#

I've retrieved an intersect entity and the two entities related to it.我检索了一个相交实体和与之相关的两个实体。

I've linked the entities to the query (to my belief).我已经将实体链接到查询(我的信念)。

When I run the code, all intersect entities appear, but I can't figure out how to get any data from them, even the name of the name.当我运行代码时,所有相交实体都会出现,但我无法弄清楚如何从中获取任何数据,甚至是名称的名称。

Please see below code: .请看下面的代码:.

private static EntityCollection GetOpportunityAndInstallationSiteIntersectEntity(IOrganizationService service)

        var installationSite = "csp_installationsite";
                    var opportunity = "opportunity";
                    var relationshipName = "csp_opportunity_csp_installationsite";
        
                    var relationshipQuery = new QueryExpression(installationSite)
                    {
                        ColumnSet = new ColumnSet(true)
                    };
        
                    var linkInstallationSite = new LinkEntity(installationSite, relationshipName, "csp_installationsiteid","csp_installationsiteid" ,JoinOperator.Inner);
                    var linkOpportunity = new LinkEntity(opportunity, relationshipName, "opportunityid", "opportunityid" ,JoinOperator.Inner);
        
                    linkInstallationSite.LinkEntities.Add(linkOpportunity);
        
                    relationshipQuery.LinkEntities.Add(linkInstallationSite);
                    var RelationshipCollection = service.RetrieveMultiple(relationshipQuery);
                    Console.WriteLine("Retrieved {0} Intersect Entities", RelationshipCollection.Entities.Count);
        
        foreach (Entity IS in RelationshipCollection.Entities)
                    {
                        Console.WriteLine("Intersect Entity:", IS["csp_name"]);
                    }
        
        return RelationshipCollection;
    


    I'd just like to know how I can get the records related to the intersect. 
    Lets call an entity A, I want to deprecate it, but it's related to Entity B in a N:N relationship.
    
    I've created a new entity, which is related to entity A in PowerAutomate.

I want all of Entity B to now be related to this Entity I made in PowerAutomate.我希望所有实体 B 现在都与我在 PowerAutomate 中创建的这个实体相关。

Any help is appreciated.任何帮助表示赞赏。

When I ran your code I could get access to the Installation Site attributes and I just modified it slightly to get the all the attributes from the opportunity.当我运行您的代码时,我可以访问安装站点属性,我只是稍微修改它以从机会中获取所有属性。

The code below loops through the name attributes of both the Opportunity and Installation Site.下面的代码循环访问机会和安装站点的名称属性。

private static EntityCollection GetOpportunityAndInstallationSiteIntersectEntity(IOrganizationService service)
{
    var installationSite = "csp_installationsite";
    var opportunity = "opportunity";
    var relationshipName = "csp_opportunity_csp_installationsite";

    var relationshipQuery = new QueryExpression(installationSite)
    {
        ColumnSet = new ColumnSet(true)
    };

    var linkInstallationSite = relationshipQuery.AddLink(relationshipName, "csp_installationsiteid", "csp_installationsiteid", JoinOperator.Inner);
    var linkOpportunity = linkInstallationSite.AddLink(opportunity, "opportunityid", "opportunityid", JoinOperator.Inner);
    linkOpportunity.EntityAlias = "opp";
    linkOpportunity.Columns.AllColumns = true;
    var RelationshipCollection = service.RetrieveMultiple(relationshipQuery);

    foreach (Entity IS in RelationshipCollection.Entities)
    {
        Console.WriteLine($"Intersect Entity: {IS["csp_name"]} {((AliasedValue)IS["opp.name"]).Value}");
    }

    return RelationshipCollection;
}

From there you will need to associate the records to the new entity and dissociate the old one从那里您需要将记录关联到新实体并分离旧实体

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 D365 C#-检索多个并且更新非常慢 - D365 C# - Retrieve Multiple and Updating Very Slow 如何通过 C# 连接到 Azure D365 Odata - How to connect to Azure D365 Odata via C# D365 中来自 IServiceProvider 的自定义服务 - Custom services from IServiceProvider in D365 D365 Business Central,我们需要使用C#代码将记录创建到Items中 - D365 Business Central, we need to create records into Items using C# code C# Entity Framework 6 加载相关实体 - C# Entity Framework 6 loading related entities 无法在无头模式下将文件上传到 D365 Selenium C# - Cannot upload file to D365 in headless mode Selenium C# D365(本地):使用QueryExpression用“ LinkedFrom”实体字段更新“ LinkedTo”实体字段 - D365 (On-Prem): Update 'LinkedTo“ Entity field with ”LinkedFrom" Entity field using QueryExpression c#与列表相交 <Tuple> 与实体清单 - c# Intersect a List<Tuple> with List of entities 将现有实体记录(竞争对手)关联到新记录(机会)crm d365 On create message - Associate existing entity records (competitor) to new record (opportunity) crm d365 On create message C# Memory 从 Dynamics 365 检索实体详细信息 - C# Out of Memory retrieving entity details from Dynamics 365
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM