0

我有如下代码:

QueryExpression query = new QueryExpression();
            query.EntityName = "new_callistyorder"; 
            ColumnSet col = new ColumnSet("new_nomororder","new_customer");
            query.ColumnSet = col;

            EntityCollection colect = service.RetrieveMultiple(query);

            string str = string.Empty;
            foreach (Entity e in colect.Entities)
            {
                if(e.Contains("new_nomororder")){
                str = str + e.Attributes["new_nomororder"].ToString();
                }
            }
            throw new InvalidPluginExecutionException(str);

通过这段代码。我能够从微软动态实体获取数据。现在,我想获取具有最大 id 的数据。如果在 SQL 查询中,它看起来像这样:“Select top 1 my_id from Account order by my_id desc”。我如何在 queryexpression 上做到这一点?谢谢

4

1 回答 1

2

您可以使用以下命令添加订单:

query.AddOrder("my_id", OrderType.Descending);

然后获取检索到的第一个元素。

var entityCollection = service.RetrieveMultiple(query);
if(entityCollection.Entities.Count<1)
{
    //perform some logic
}
于 2015-11-04T07:51:25.710 回答