我需要限制从数据库返回的客户博的数量,因为我正在搜索部分客户名称,目前在搜索“a”时我得到了 600 多个博。我想将其限制为 20。我现在的代码是
public IEnumerable<Customer> FindCustomers(string partialCustomerName)
{
if (string.IsNullOrEmpty(partialCustomerName))
throw new ArgumentException("partialCustomerName must be at least one character long");
var criteria = Criteria.Create<Customer, string>(cust => cust.CustomerName, Criteria.ComparisonOp.Like, partialCustomerName + "%");
return Broker.GetBusinessObjectCollection<Customer>(criteria);
}
请您参考如下方法:
我现在无法对此进行测试,但您应该可以使用 LoadWithLimit() 方法进行测试。 totalRecords 变量将保存找到的总结果数,以防您想要包含一些信息,例如“显示 20 个 totalRecords 结果”。
public IEnumerable<Customer> FindCustomers(string partialCustomerName)
{
if (string.IsNullOrEmpty(partialCustomerName))
throw new ArgumentException("partialCustomerName must be at least one character long");
var criteria = Criteria.Create<Customer, string>(cust => cust.CustomerName, Criteria.ComparisonOp.Like, partialCustomerName + "%");
int totalRecords;
return Broker.GetBusinessObjectCollection<Customer>().LoadWithLimit(criteria, 0, 20, ref totalRecords);
}
