Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5969693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:16:01+00:00 2026-05-22T20:16:01+00:00

I need to restrict the number of customer bo’s returned from the database as

  • 0

I need to restrict the number of customer bo’s returned from the database as I am searching for a partial customer name and at the moment I get over 600 bo’s when searching for ‘a’. I would like to restrict this to 20. My code at the moment is

    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);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:16:02+00:00Added an answer on May 22, 2026 at 8:16 pm

    Till is on the right track there, but did not give the correct syntax.
    The broker is used to load collections from the current Data Accessor, not for creating new ones. So the code would then be:

    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;
        var col = new BusinessObjectCollection<Customer>();
        col.LoadWithLimit(criteria, "CustomerName", 0, 20, ref totalRecords);
        return col;
    }
    

    That should do it!
    Please award the answer to Till, not me. He did the most research. I just corrected the syntax 🙂

    EDIT:
    After comments below about the ugly API, I will include suggested changes to the method to make it look cleaner (Thanks for your suggestion @GloryDev):

    public IEnumerable<Customer> FindCustomers(string partialCustomerName)
    {
        if (string.IsNullOrEmpty(partialCustomerName)) 
          throw new ArgumentException("partialCustomerName must be at least one character long");
        var col = new BusinessObjectCollection<Customer>();
        col.LoadWithLimit("CustomerName Like " + partialCustomerName + "%", "CustomerName", 20);
        return col;
    }
    

    The Second parameter is the field to order by, which is necessary for a fetch with limits to make any sense. Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to restrict the development users from creating new schedules for SQL Agent
I need to restrict users in my application to login from a one computer
I query my Database using NHibernate. Now I need to restrict the data being
I need to restrict a controller in CI 2 to only run from command
I need to restrict POST request from specific domain. As far I know, HTTP_REFERER
I basically need to restrict the number of logged in users in my application.
I need to restrict users from opening an Excel (.xls) file with notepad. I
I need to restrict the resulting rows from each table/object depending on my security
I have a requirement that I need to restrict my kids from browsing some
I need to restrict user access to filebrowser using permissions. For example, only users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.