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

  • Home
  • SEARCH
  • 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 8354807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:40:08+00:00 2026-06-09T09:40:08+00:00

I am building .net application using nhibernate for mapping data to entities. I am

  • 0

I am building .net application using nhibernate for mapping data to entities. I am still newbie in object oriented programming and now I have this question:

I have entities such as Customer, Order, Product etc. I can fetch objects by nhibernate from data from database and list customers etc. But what if I want to list customers with its order totals? These are not data for customer entity, nor order entity. How to fetch and list such combined data? Should they have its own data transfer object or is here better way how to do this?

  • 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-06-09T09:40:09+00:00Added an answer on June 9, 2026 at 9:40 am

    Have an additional entity, CustomerList, which will hold the Customer object.

    The CustomerList will have a method to sort the list according to the order totals, which will be done by accessing each memeber’s order totals and comparing them.

    In PHP, I would do something like so (That is only an example, in real code there may be other things you’ll need to take into account).

    <?php
    
    /**
     * Describe a single customer object
     */
    class Customer {
    
        /** @var Order[] List of orders */
        private $orders = array();
    
        /**
         * Add an order to the order list.
         *
         * @param Order $order
         */
        public function addOrder(Order $order) {
            if (!in_array($order, $this->orders, true)) {
                $this->orders[] = $order;
            }
        }
    
        /**
         * Get an order by numeric index.
         *
         * @param int $index
         *
         * @return Order
         */
        public function getOrder($index) {
            return $this->orders[$index];
        }
    
        /**
         * Get total number of orders for customer.
         *
         * @return int
         */
        public function getOrdersTotal() {
            return count($this->orders);
        }
    }
    
    /**
     * Describe a single order.
     * I didn't include any information here because it's not relevant.
     */
    class Order {
    
    }
    
    /**
     * Describe a list of customers.
     */
    class CustomerList {
    
        /** @var Customer[] List of customers */
        private $customers;
    
        /**
         * Add a customer to the list
         *
         * @param Customer $customer
         */
        public function addCustomer(Customer $customer) {
            $this->customers[] = $customer;
        }
    
        /**
         * The sorting function.
         * Compare the orders total and return 1/0/-1 accordingly.
         *
         * @param Customer $a
         * @param Customer $b
         *
         * @return int
         */
        public function sort($a, $b) {
            if ($a->getOrdersTotal() === $b->getOrdersTotal()) {
                return 0;
            }
            return ($a->getOrdersTotal() > $b->getOrdersTotal()) ? 1 : -1;
        }
    
        /**
         * Call the sorting function on the customer list
         */
        public function sortCustomers() {
            usort($this->customers, array($this, "sort"));
        }
    
        /**
         * Return the full customer array.
         *
         * @return Customer[]
         */
        public function getCustomers() {
            return $this->customers;
        }
    }
    
    //Instantiation
    $cList = new CustomerList();
    
    $customer1 = new Customer();
    $customer2 = new Customer();
    $customer3 = new Customer();
    
    $order1 = new Order();
    $order2 = new Order();
    $order3 = new Order();
    $order4 = new Order();
    $order5 = new Order();
    $order6 = new Order();
    
    $customer1->addOrder($order1);
    $customer1->addOrder($order2);
    
    $customer2->addOrder($order3);
    
    $customer3->addOrder($order4);
    $customer3->addOrder($order5);
    $customer3->addOrder($order6);
    
    $cList->addCustomer($customer1);
    $cList->addCustomer($customer2);
    $cList->addCustomer($customer3);
    
    //List customers before sorting
    var_dump($cList->getCustomers());
    
    $cList->sortCustomers();
    
    //List customers after sorting
    var_dump($cList->getCustomers());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In have my application configured in asp.net. I am using ajaxcontroltoolkit. After building the
I'm building an ASP.NET web application using NHibernate and a legacy database. In that
I'm building an ASP.NET application. I'm using a ListView to show some Entities however
I am currently building an application using ASP.NET MVC. The data entry pages are
I'm building an ASP.net application using Visual Studio Web Developer 2010 Express and have
We're building a business application using Microsoft ASP.NET MVC 3. Some views are now
We are currently building the framework for developing a C# .net application using visual
I am building a Web Application using asp.net (C#). I come from windows forms
I am building a web application using ASP.NET MVC that has two very distinct
I am building a AJAX intensive web application (using ASP.NET, JQuery, and WCF web

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.