簡體   English   中英

獲取ms動態CRM中的關聯記錄

[英]get associated records in ms dynamics crm

您好,您可以從ms crm 2013中的campaignlist_association獲取相關記錄。嘗試了大量不同的版本。

這是最后一個:

System.Guid campaignId = ((EntityReference)entity.Attributes["regardingobjectid"]).Id;


var list = (from c in EntityCon.CampaignSet
            join l in EntityCon.ListSet on c.campaignlist_association equals l.campaignlist_association
            where c.CampaignId == campaignId select c).First();

錯誤訊息

join子句中的表達式之一的類型不正確。 調用“加入”時類型推斷失敗

指示與equals表達式一起使用的屬性的類型必須匹配,例如,它們都是Int32Guid

確保類型l.campaignlist_association相同類型c.campaignlist_association

我將使用以下代碼來獲取關聯的實體記錄。 根據您的要求更改列集。

private EntityCollection GetAssociatedEntityItems(string relationshipName, string relatedEntityName, string entityName, Guid entityId)
    {
        EntityCollection result = null;
            QueryExpression query = new QueryExpression();
            query.EntityName = relatedEntityName;
            query.ColumnSet = new ColumnSet(false);
            Relationship relationship = new Relationship();
            relationship.SchemaName = relationshipName;
            relationship.PrimaryEntityRole = EntityRole.Referencing;
            RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection();
            relatedEntity.Add(relationship, query);
            RetrieveRequest request = new RetrieveRequest();
            request.RelatedEntitiesQuery = relatedEntity;
            request.ColumnSet = new ColumnSet(true);

            request.Target = new EntityReference
            {
                Id = entityId,
                LogicalName = entityName
            };
            RetrieveResponse response = (RetrieveResponse)serviceProxy.Execute(request);
            RelatedEntityCollection relatedEntityCollection = response.Entity.RelatedEntities;
            if (relatedEntityCollection.Count > 0)
            {
                if (relatedEntityCollection.Values.Count > 0)
                {
                    result = (EntityCollection)relatedEntityCollection.Values.ElementAt(0);
                }
            }
        return result;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM