我有此代码:
protected readonly IMsgSetRequest RequestMsgSet = null;
protected IMsgSetResponse ResponseMsgSet = null;
public string GetAllCustomer(bool IsActiveOnly = true)
{
RequestMsgSet.ClearRequests();
ICustomerQuery CustomerQueryRq = RequestMsgSet.AppendCustomerQueryRq();
if (IsActiveOnly)
{
if (CustomerQueryRq != null)
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(
ENActiveStatus.asActiveOnly);
}
else {
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);
}
ResponseMsgSet = SessionManager.DoRequests(RequestMsgSet);
return(ResponseMsgSet.ToXMLString());
}
Console.WriteLine(GetAllCustomer());
它返回以下内容:
<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<CustomerQueryRs requestID="0" statusCode="1000" statusSeverity="Error" statusMessage="There has been an internal error when processing the request." />
</QBXMLMsgsRs>
</QBXML>
我怀疑DoRequests内存不足,因为我有110,000个客户。
如何确认DoRequests内存不足?
如何重写此代码以使用更少的内存?
答案 0 :(得分:2)
您可以使用过滤器来获取数据,例如:名称范围(a-i,j-r比s-z)过滤器,日期范围过滤器,名称以过滤器开头以及其他一些过滤器。
这也可用于仅获取所需的内容:全名和帐户号。
这样,您可以消耗更少的内存使用量。看看下面的示例代码:
public IList<CustomerModelQB> GetAllCustomer(string fromName = "a", string toName = "z", bool IsActiveOnly = true)
{
RequestMsgSet.ClearRequests();
ICustomerQuery CustomerQueryRq = RequestMsgSet.AppendCustomerQueryRq();
if (IsActiveOnly)
{
if (CustomerQueryRq != null)
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(
ENActiveStatus.asActiveOnly);
}
else
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);
//CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.MaxReturned.SetValue(3);
//Set field value for FromName
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameRangeFilter.FromName.SetValue(fromName);
//Set field value for ToName
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameRangeFilter.ToName.SetValue(toName);
CustomerQueryRq.IncludeRetElementList.Add("FullName");
CustomerQueryRq.IncludeRetElementList.Add("AccountNumber");
ResponseMsgSet = SessionManager.DoRequests(RequestMsgSet);
return WalkCustomerQuery(ResponseMsgSet);
}
进一步,您可以参考this问题以按字母顺序排列。