concept order object in category .net

appears as: n Order object, Order object, Order objects
.NET Core in Action

This is an excerpt from Manning's book .NET Core in Action.

Listing 5.28 shows how you’ll create the records in the Order and SendEmailCommand tables. The CreateOrder method, shown in the following listing, takes an Order object with all the properties filled in (except the Id property).

Filling in the Order object

The only method you haven’t yet completed is OrderPart. You’ve seen before that not populating all the properties in the Order object will cause an exception. OrderPart is a helper method to hydrate the Order object and create the order, as shown in the following listing.

Listing 5.35. OrderPart helper method to hydrate the Order object and create the order
public void OrderPart(PartType part, int count)
{
  var order = new Order() {
    PartTypeId = part.Id,
    PartCount = count,
    PlacedDate = DateTime.Now
  };
  order.Part = context.Parts.Single(p => p.Id == order.PartTypeId);
  order.Supplier = context.Suppliers.First(                          #1
    s => s.PartTypeId == part.Id);
  order.SupplierId = order.Supplier.Id;
  context.CreateOrder(order);
}