Step 7 - Enhancing the Order Business Object
In this step you will enhance the Order business object. We'll provide very detailed instructions as you enhance your first business object, then we'll abbreviate the instructions a bit for other business objects.
Adding Methods to the Order Business Object
When you generated business objects for this project, you specified that the Business Layer Generator should create partial classes for the key business object source code files. These partial classes ensure that you can place code in one half of the partial class and not have it overwritten if you choose to regenerate the business object in the future. With this in mind, you will be manually adding the following methods to the Order.Partial.cs source code file.
- Click the Order.Partial.cs file to open it in the code editor.
- According to the analysis and design we did earlier, the Order object needs two methods: GetOrderByOrderID() and GetOrdersByCustomerID() . Let's create GetOrderByOrderID() first.
Add the following code below the HookConstructor() method:
public OrderEntity GetOrderByOrderID(int orderID) { IQueryable<OrderEntity> query = from order in this.ObjectContext.OrderEntities where order.OrderID == orderID select order; return this.GetEntity(query); }
This method accepts a single integer orderID parameter which is used in the filter portion of the LINQ statement. This LINQ query is passed to GetEntity() which in turn sends the query to the Object Context to be execute. It returns an entity containing the specified order (behind the scenes it's also stored in the business object's Entity property for future reference). The GetEntity() method returns an entity object of the type declared in the generic class definition, in this case, <OrderEntity>:
public partial class Order : ABusinessObject<OrderEntity>
{ - Now you will add an XML Comment to the method definition. To do this, first make sure there is an empty line before the new GetOrderByOrderID() method. Place your cursor directly above the method definition as shown here:

Next, type three forward slashes (///). The C# editor automatically inserts an XML Comment template above your method definition:
/// <summary> /// /// </summary> /// <param name="orderID"></param> /// <returns></returns>
Enter the following descriptions in the XML comment:
/// <summary> /// Returns an OrderEntity object populated with the specified order /// </summary> /// <param name="orderID">Order ID</param> /// <returns>OrderEntity object</returns>
- Next, add the following GetOrdersByCustomerID() method declaration beneath the GetOrderByOrderID() method (you can just add code and comments in one step this time):
/// <summary> /// Returns a strongly typed list of OrderEntity objects for the specified customer /// </summary> /// <param name="customerID">Customer ID</param> /// <returns>Strongly Typed List of OrderEntity objects</returns> public mmBindingList<OrderEntity> GetOrdersByCustomerID(string customerID) { IQueryable<OrderEntity> query = from order in this.ObjectContext.OrderEntities where order.CustomerID == customerID select order; return this.GetEntityList(query); }
This method returns a strongly typed list of OrderEntity objects for the specified customer. This first line of code creates a LINQ query that queries against the project's Entity Data Model--specifically from the object context's OrderEntities. The second line of code passes the query to the MM .NET GetEntity() method which executes the query and returns the specified order entity object.
- In the Solution Explorer, right-click your solution and select Rebuild from the shortcut menu.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 02/10/26
Comment or report problem with topic
