Получить XML-фильтр по первичному ключу без имени - PullRequest
0 голосов
/ 07 мая 2018

Мне известно, что ниже условие атрибута = 'primaryKey' не является допустимым полем, интересно, есть ли какой-то синтаксис выборки xml, который позволяет фильтровать первичный ключ, не зная имени ключа

[TestMethod]
public async System.Threading.Tasks.Task ShoulRetrieveAnyEntity(OrganizationServiceProxy _oragnizationServiceProxy)
{
    var entityName = "account";
    var entityGuid = "7004d3c1-3147-e811-a95e-000d3a10877d";

    string xml = "<fetch distinct='false' version='1.0' output-format='xml-platform' mapping='logical' no-lock='true'>" +
                     "<entity name='" + entityName + "'>" +
                        "<all-attributes />" +
                            "<filter type='and'>" +
                                "<condition attribute='primaryKey' operator='eq' value='{" + entityGuid + "}' />" +
                            "</filter>" +
                        "</entity>" +
                    "</fetch>";

    RetrieveMultipleRequest rmRequest = new RetrieveMultipleRequest() { Query = new FetchExpression(xml) };
    EntityCollection eResults = ((RetrieveMultipleResponse)_oragnizationServiceProxy.Execute(rmRequest)).EntityCollection;
    if (eResults.Entities.Count > 0)
    {
        foreach (KeyValuePair<string, object> attribute in eResults.Entities[0].Attributes)
            {
                Console.WriteLine(attribute.Key + ": " + attribute.Value.ToString());
            }
        }
    }
}

1 Ответ

0 голосов
/ 07 мая 2018

Не усложняйте это. CRM создает Первичный ключ из Имя схемы объекта путем добавления к нему идентификатора для всех объектов.

Например: счет accountid, возможность opportunityid и т. Д.

string xml = "<fetch distinct='false' version='1.0' output-format='xml-platform' mapping='logical' no-lock='true'>" +
                     "<entity name='" + entityName + "'>" +
                        "<all-attributes />" +
                            "<filter type='and'>" +
                                "<condition attribute='" + entityName + "id' operator='eq' value='{" + entityGuid + "}' />" +
                            "</filter>" +
                        "</entity>" +
                    "</fetch>";

Тем не менее, если вы хотите сделать это в соответствии с общими рекомендациями - Прочитайте это .

...