简体   繁体   English

C#中的Microsoft CRM QueryExpression

[英]Microsoft CRM QueryExpression in C#

i have code like below: 我有如下代码:

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);

Trough this code. 通过此代码。 I am able to get data from microsoft dynamic entity. 我能够从Microsoft动态实体获取数据。 Now, i want to get the data which have biggest id. 现在,我想获取具有最大id的数据。 If in SQL Query, it would be looks something like this : "Select top 1 my_id from Account order by my_id desc". 如果在SQL查询中,则将类似于以下内容:“按my_id desc从帐户顺序中选择前1个my_id”。 How can i do that on queryexpression ? 如何在queryexpression上执行此操作? Thanks 谢谢

You can add the order by using this: 您可以使用以下命令添加订单:

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

and then getting the first element retrieved. 然后获取第一个元素。

var entityCollection = service.RetrieveMultiple(query);
if(entityCollection.Entities.Count<1)
{
    //perform some logic
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM