C# 在没有名称的主键上获取XML筛选器

C# 在没有名称的主键上获取XML筛选器,c#,sql,dynamics-crm,dynamics-365,fetchxml,C#,Sql,Dynamics Crm,Dynamics 365,Fetchxml,我知道下面的条件属性class='primaryKey'不是有效字段,我想知道是否有一些获取xml语法允许您在不知道密钥名称的情况下对主键进行筛选 [TestMethod] public async System.Threading.Tasks.Task ShoulRetrieveAnyEntity(OrganizationServiceProxy _oragnizationServiceProxy) { var entityName = "account"; var entit

我知道下面的条件属性class='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());
            }
        }
    }
}
[TestMethod]
public async System.Threading.Tasks.Task ShoulRetrieveAnyEntity(OrganizationServiceProxy\u或gnizationServiceProxy)
{
var entityName=“帐户”;
var entityGuid=“7004d3c1-3147-e811-a95e-000d3a10877d”;
字符串xml=“”+
"" +
"" +
"" +
"" +
"" +
"" +
"";
RetrieveMultipleRequest rmRequest=新的RetrieveMultipleRequest(){Query=新的FetchExpression(xml)};
EntityCollection eResults=((RetrieveMultipleResponse)或gnizationServiceProxy.Execute(rmRequest)).EntityCollection;
如果(eResults.Entities.Count>0)
{
foreach(eResults.Entities[0].Attributes中的KeyValuePair属性)
{
Console.WriteLine(attribute.Key+”:“+attribute.Value.ToString());
}
}
}
}

不要把它复杂化。CRM通过为所有实体添加“id”,从实体架构名称创建主键

例如:帐户是
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>";
string xml=“”+
"" +

我可以从执行上下文中获取此架构名称?我也可以@GregDegruy yes-如果其插件/workflow.service.Retrieve将通过过滤PK-
service.Retrieve(EntityLogicalname、Entityguid、new ColumnSet(true))获取单个记录
。但是RetrieveMultiple可以用于筛选任何列,您也可以在fetchxml中询问。这就是为什么我以相同的方式回答:)