计算Acumatica中任何类型实体的数量

计算Acumatica中任何类型实体的数量,acumatica,Acumatica,在Acumatica参考(帮助->Acumatica框架->API参考->BQL->分组和聚合->聚合函数)中,有以下代码片段 PXResult<Table> res = PXSelectGroupBy<Table, Aggregate<Count>>.Select(this).RowCount; PXResult= PXSelectGroupBy.Select(this).RowCount; 但当我使用实体UPCompany执行时,我收到以下错误消息:

在Acumatica参考(帮助->Acumatica框架->API参考->BQL->分组和聚合->聚合函数)中,有以下代码片段

PXResult<Table> res =
PXSelectGroupBy<Table, Aggregate<Count>>.Select(this).RowCount;
PXResult=
PXSelectGroupBy.Select(this).RowCount;
但当我使用实体UPCompany执行时,我收到以下错误消息:

System.ArgumentNullException was unhandled by user code
  HResult=-2147467261
  Message=Value cannot be null.
  Source=mscorlib
  StackTrace:
       at System.RuntimeType.MakeGenericType(Type[] instantiation)
       at PX.Data.Select4`2.OrderByNew(Type newOrderBy)
       at PX.Data.PXView.prepareSorts(String[] sortcolumns, Boolean[] descendings, Object[] searches, Int32 topCount, Boolean& needOverrideSort, Boolean& anySearch, Boolean& resetTopCount)
       at PX.Data.PXView.Select(Object[] currents, Object[] parameters, Object[] searches, String[] sortcolumns, Boolean[] descendings, PXFilterRow[] filters, Int32& startRow, Int32 maximumRows, Int32& totalRows)
       at PX.Data.PXSelectBase`1.selectBound[Resultset](BqlCommand command, Boolean readOnly, PXGraph graph, Int32 startRow, Int32 totalRows, Object[] currents, Object[] pars)
       at PX.Data.PXSelectBase`1.select[Resultset](BqlCommand command, Boolean readOnly, PXGraph graph, Int32 startRow, Int32 totalRows, Object[] pars)
       at PX.Data.PXSelectGroupBy`2.SelectWindowed[Resultset](PXGraph graph, Int32 startRow, Int32 totalRows, Object[] pars)
       at PX.Data.PXSelectGroupBy`2.Select[Resultset](PXGraph graph, Object[] pars)
       at stackOverflowSync.UsrstackOverflowSettingsMaint.ItemsForSync(UsrstackOverflowSettings settingsSelect) in C:\sourceCode\stackOverflow\stackOverflow\Acumatica_ERPSync\Acumatica_ERPSync\stackOverflowSync\UsrstackOverflowSettingsMaint.cs:line 26
       at stackOverflowSync.UsrstackOverflowSettingsMaint.Persist() in C:\sourceCode\stackOverflow\stackOverflow\Acumatica_ERPSync\Acumatica_ERPSync\stackOverflowSync\UsrstackOverflowSettingsMaint.cs:line 173
       at PX.Data.PXSave`1.<Handler>d__2.MoveNext()
       at PX.Data.PXAction`1.<Press>d__31.MoveNext()
  InnerException: 
System.ArgumentNullException未由用户代码处理
HResult=-2147467261
Message=值不能为null。
Source=mscorlib
堆栈跟踪:
位于System.RuntimeType.MakeGenericType(类型[]实例化)
在PX.Data.Select4`2.OrderByNew(键入newOrderBy)
在PX.Data.PXView.prepareSorts(字符串[]sortcolumns,布尔值[]子代,对象[]搜索,Int32 topCount,布尔值和需要重写,布尔值和任意搜索,布尔值和重置topCount)
在PX.Data.PXView.Select(对象[]当前、对象[]参数、对象[]搜索、字符串[]排序列、布尔[]下降、PXFilterRow[]过滤器、Int32和startRow、Int32 maximumRows、Int32和totalRows)
在PX.Data.PXSelectBase`1.selectBound[Resultset](BqlCommand命令,布尔只读,PXGraph图形,Int32 startRow,Int32 totalRows,Object[]currents,Object[]pars)
在PX.Data.PXSelectBase`1.select[Resultset](BqlCommand命令,布尔只读,PXGraph图形,Int32 startRow,Int32 totalRows,Object[]pars)
在PX.Data.PXSelectGroupBy`2.SelectWindowed[Resultset](PXGraph图形、Int32 startRow、Int32 totalRows、对象[]PAR)
在PX.Data.PXSelectGroupBy`2.选择[Resultset](PXGraph图形,对象[]PAR)
在C:\sourceCode\stackOverflow\stackOverflow\Acumatica\u ERPSync\Acumatica\u ERPSync\stackOverflowSync\usrstackoverflowsettingmaint.ItemsForSync(UsrstackOverflowSettings设置选择)中的stackOverflowSync.UsrstackOverflowSettings maint.cs:第26行
在C:\sourceCode\stackOverflow\stackOverflow\Acumatica\u ERPSync\Acumatica\u ERPSync\stackOverflowSync\usrstackoverflowsettingmaint.cs中的stackOverflowSync.usrstackoverflowsettingmaint.Persist()处:第173行
在PX.Data.PXSave`1.d_uuu2.MoveNext()中
在PX.Data.PXAction`1.d_uu31.MoveNext()中
内部异常:

所以我的问题是:如何正确地执行Acumatica引用中的代码片段,以便接收包括UPCompany在内的所有行数?

我找到了原因。UPCompany不是可使用PXSelect、PXSelectGroupBy的实体。我想可能是因为UPCompany和数据库没有直接的通信。虽然这很奇怪,但对于UPCompany PXSelect和PXSelectGroupBy之外的其他实体来说,效果相当不错。我以以下方法结束:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PX.Data;

namespace PX.Data
{
    public static class ExtMethods
    {
        public static int? GetNumberOfEntities<T>(this PXGraph graph) where T : class, IBqlTable, new()
        {
            PXResult<T> res = PXSelectGroupBy<T, Aggregate<Count>>.Select(graph);
            return res.RowCount;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用PX数据;
名称空间PX.Data
{
公共静态类ext方法
{
公共静态int?GetNumberOfEntities(这个PXGraph图),其中T:class,IBqlTable,new()
{
PXResult res=PXSelectGroupBy.Select(图形);
返回res.RowCount;
}
}
}
用于计算实体数