gpt4 book ai didi

c# - 在 CRM 动态 SDK.Query.QueryExpression 中使用选择计数

转载 作者:行者123 更新时间:2023-11-30 21:55:21 25 4
gpt4 key购买 nike

使用 c#,我需要使用 Microsoft Dynamics 2015 的 SDK.Query.QueryExpression 库构建查询。我无法弄清楚如何排序和计算出现次数。

我想统计每个产品在所有机会中的使用次数。

sql 查询本身相当简单:

SELECT b.Name, count(a.ProductId) as 'accurances'
FROM [ProkonCRM_MSCRM].[dbo].[OpportunityProductBase] a,
[ProkonCRM_MSCRM].[dbo].[ProductBase] b
where a.ProductId = b.ProductId
group by b.name

最佳答案

据我所知,QueryExpressions 不支持聚合函数。您可能需要为此查看 FetchXML,因为那里支持聚合函数。以下是一些使用 FetchXML 实现您想要的示例: https://msdn.microsoft.com/en-us/library/gg309565.aspx#count

FetchXML 中的示例(未经测试,您的实体名称可能不同,我假设它是 N:N 关系)

<fetch distinct='false' mapping='logical' aggregate='true'> 
<entity name='product'>
<attribute name='name' alias='productName' groupby='true'/>
<link-entity name='opportunityproduct' from='opportunityid' to='opportunityid'>
<attribute name='productid' alias='occurences' aggregate='count' />
</link-entity>
</entity>
</fetch>

关于c# - 在 CRM 动态 SDK.Query.QueryExpression 中使用选择计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32375205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com