public static EntityCollection GetContactsInAccount(IOrganizationService ser, Guid accountid, ColumnSet columnset)
{
try
{
QueryExpression sorgu = new QueryExpression()
{
EntityName = "contact",
ColumnSet = columnset,
Criteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("statecode",ConditionOperator.Equal,(int)ContactState.Active)
}
},
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName="contact",
LinkFromAttributeName="parentcustomerid",
LinkToEntityName = "account",
LinkToAttributeName = "accountid",
LinkCriteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("accountid",ConditionOperator.Equal,accountid)
}
}
}
}
};
EntityCollection ec = null;
ec = ser.RetrieveMultiple(sorgu);
if (ec != null && ec.Entities.Count != 0)
return ec;
else
return new EntityCollection();
}
catch (Exception ex)
{
throw ex;
}
}
Metot Kullanımı
EntityCollection ecContacts = CrmManagerStatic.GetContactsInAccount(crmServiceAdmin, item, new ColumnSet(new string[] { "contactid", "parentcustomerid" }));
if (ecContacts != null && ecContacts.Entities.Count != 0)
{
foreach (var itemContact in ecContacts.Entities)
{
}
}
Hiç yorum yok:
Yorum Gönder