繁体   English   中英

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

[英]Use select count in CRM dynamics SDK.Query.QueryExpression

使用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/zh-cn/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>

我假设您具有CRM 2015的本地实现。基于该假设,您可以选择直接查询CRM数据库并使用C#(例如,使用Microsoft.Data.SQL库)执行SQL查询。

查询FilteredViews非常重要,因为这是直接查询CRM数据库的推荐方法。

FilteredViews参考: https : //technet.microsoft.com/zh-cn/library/dn531182.aspx

暂无
暂无

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

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