我知道下面的条件属性=' 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());
}
}
}
}
答案 0 :(得分:1)
例如:帐户为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>";
如果您希望以通用的最佳实践方式执行此操作 - Read this。