[英]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.