使用早期绑定从 CRM 中检索前一条记录

Retrieve top one record from CRM using early bound

我想使用早期绑定查询表达式从我的 CRM 实体中检索最多的记录。

我写成:

QueryExpression opportunityProductsQuery = new QueryExpression
        {
            EntityName = PCSEPortal.oph_ophthalmicclaim.EntityLogicalName,
            ColumnSet = new ColumnSet("Name"),
            Criteria = new FilterExpression
            {
               new ConditionExpression
                        {
                            //condition
                        }
            }
        };
        return "";

但是我不知道这里怎么写 where 条件和 top 1 order by Desc 条件。

对于where条件,我有列作为投稿渠道

- Logical name - oph_submissionchannel
- Schema Name  - oph_SubmissionChannel

并按 Guid 或任何唯一 ID 订购。

这里怎么写查询表达式?或者还有其他更好的选择吗?为此,我试图避免使用 FetchXML。

您必须使用 PagingInfo 来实现此目的。

opportunityProductsQuery.PageInfo.Count = 1;

Read more。此示例说明如何使用 LinkEntity、LinkCriteria、降序排序和 PageInfo 来获取结果。

    LinkEntity le = opportunityProductsQuery.AddLink(PCSEPortal.oph_submissionchannel.EntityLogicalName, “oph_submissionchannelid”, “2ndentityname2”);
    le.Columns = new ColumnSet(“oph_submissionchannelid”);
    le.LinkCriteria.AddCondition(“oph_submissionchannelid”, ConditionOperator.Equal, Guid);   //where condition
    opportunityProductsQuery.AddOrder(“modifiedon”, OrderType.Descending);
    opportunityProductsQuery.PageInfo = new PagingInfo();
    opportunityProductsQuery.PageInfo.Count = 1;
    opportunityProductsQuery.PageInfo.PageNumber = 1;

    EntityCollection entitycolls = service.RetrieveMultiple(equery);

您还可以使用 QueryExpression 的 TopCount 属性:

QueryExpression opportunityProductsQuery = new QueryExpression
{
    EntityName = PCSEPortal.oph_ophthalmicclaim.EntityLogicalName,
    TopCount = 1,
    ColumnSet = new ColumnSet("Name")...
};