[英]get associated records in ms dynamics crm
Hi to get associated records from campaignlist_association in ms crm 2013. Tried tons of different variations. 您好,您可以从ms crm 2013中的campaignlist_association获取相关记录。尝试了大量不同的版本。
This is last one: 这是最后一个:
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();
The error message 错误讯息
The type of one of the expressions in the join clause is incorrect.
join子句中的表达式之一的类型不正确。 Type inference failed in the call to 'Join'
调用“加入”时类型推断失败
indicates that the types of the properties used with the equals expression must match, eg that they are both Int32
or Guid
. 指示与equals表达式一起使用的属性的类型必须匹配,例如,它们都是
Int32
或Guid
。
Make sure that the type l.campaignlist_association
is the same as the type c.campaignlist_association
. 确保类型
l.campaignlist_association
相同类型c.campaignlist_association
。
I would use code as follows to get the associated entity records. 我将使用以下代码来获取关联的实体记录。 Change the column set as per your requirement.
根据您的要求更改列集。
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.