您好,以获取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();
答案 0 :(得分:0)
错误消息
join子句中某个表达式的类型不正确。调用“加入”
时,类型推断失败
表示与equals表达式一起使用的属性类型必须匹配,例如它们都是Int32
或Guid
。
确保l.campaignlist_association
类型与c.campaignlist_association
类型相同。
答案 1 :(得分:0)
我会使用以下代码来获取关联的实体记录。根据您的要求更改列集。
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;
}