简体   繁体   English

从实体的数字字段中选择最大数量(Dynamics CRM 2016)

[英]Select Maximum number from a numeric field in an entity (Dynamics CRM 2016)

What is the best way to retrieve the maximum value from a numeric field in an entity? 从实体中的数字字段检索最大值的最佳方法是什么? Something like this in SQL Server: Select MAX(NumbericFieldName) From TableName . 在SQL Server中类似这样: Select MAX(NumbericFieldName) From TableName

I tried this: 我尝试了这个:

var documentno = XrmContext.CreateQuery("nychro_traportaldocumentupload").Max(c => c.GetAttributeValue<Int32?>("nychro_portaldocumentreviewid"));

But I get the error "MAX is not supported" 但出现错误“不支持MAX”

What is the best way to resolve this? 解决此问题的最佳方法是什么?

The following linq code, should be able to accomplish your requirement: 以下linq代码应该可以满足您的要求:

var documentno = (for a in XrmContext.CreateQuery("nychro_traportaldocumentupload")
                 orderby a.nychro_portaldocumentreviewid descending
                 select a).FirstOrDefault()

You have to use fetchxml query & do a FetchExpression to fetch the result. 您必须使用fetchxml查询并执行FetchExpression来获取结果。

<fetch distinct='false' mapping='logical' aggregate='true'> 
    <entity name='nychro_traportaldocumentupload'> 
       <attribute name='nychro_portaldocumentreviewid' alias='nychro_portaldocumentreviewid_max' aggregate='max' /> 
    </entity> 
</fetch>

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

相关问题 从2011年到2016年升级Dynamics CRM - Upgrading Dynamics CRM from 2011 to 2016 Microsoft Dynamics CRM 2016年 - Microsoft Dynamics CRM 2016 如何在 Dynamics CRM 2016 中使用 DiscoveryService 获取实体中的项目列表? - How to get list of items in an entity using DiscoveryService in Dynamics CRM 2016? Dynamics CRM 2016 c#使用尚不存在的实体的ID - Dynamics CRM 2016 c# use id of not yet existing entity Dynamics CRM 2013 工作流 C# 从链接实体中提取字段 - Dynamics CRM 2013 Workflow C# Extract Field from Linked Entity Microsoft Dynamics CRM设置相关实体​​的字段值 - Microsoft Dynamics CRM set field value of related entity Microsoft Dynamics CRM 注释实体错误的“创建者”字段值 - Microsoft Dynamics CRM Annotation Entity wrong "Created by" Field value 使用QueryExpression选择一个实体? C#Dynamics CRM Online 2015年 - Select an Entity using QueryExpression? C# Dynamics CRM Online 2015 如何使用ssis的脚本组件将票证编号(查找字段)插入MS Dynamics CRM定价批准产品(自定义实体) - How to insert Ticket Number(lookup field) to MS Dynamics CRM Pricing Approval Products(Custom entity) using ssis's script component Dynamics CRM 2016 PluginProfiler System.TypeLoadException - Dynamics CRM 2016 PluginProfiler System.TypeLoadException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM