2

Say I have a product listing backed by a SQL table. It's a large data model (truncated here for brevity) but let's say looks like this:

public class Product {
    public int Id { get; set; }
    public int Number { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public decimal Cost { get; set; }
    public int UnitsOnHand { get; set; }
    public int Ordinal { get; set; }
    public int Sku12 { get; set; }
    public string Color { get; set; }
    public Vendor Vendor { get; set; }
    public Image PrimaryImage { get; set; }
    public User CreatedBy { get; set; }
    public DateTime CreatedOn { get; set; }
    public ICollection<Image> Images { get; set; }
    public ICollection<Category> Categories { get; set; }
    public ICollection<Coupon> Coupons { get; set; }
    public ICollection<Tag> Tags { get; set; }
    public ICollection<ProductOption> Options { get; set; }
}

I am getting hung up on something like a product listing (index) page where I only need a small subset of Product to be returned in a collection, like:

public class ProductBasic {
    public int Id { get; set; }
    public int Number { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public int UnitsOnHand { get; set; }
}

public ActionResult SearchProducts(string keyword) {
    IEnumerable<ProductBasic> result = _productService.Search(keyword);
    return View(result);
}

Just enough data that a table/grid could be constructed before the detail page is selected for the desired entity and the high-fidelity Product would be returned, complete with its associated Image, Category, Coupon, Tag and ProductOption collections (FK records).

I am struggling both with naming convention as well as handling code first since these objects represent the same physical table; that is, I do not need ProductBasic created in the database.

My intent is to have a lighter-weight object to send a collection to the client, until a detailed object is required. What is the standard naming convention for smaller, subset data models like this? I have been kicking around ProductBasic, ProductStub, ProductRoot, ProductSnip and ProductShort.

Then, Product represents my table, and I need to exclude ProductBasic from the code first.

jbwebtech
  • 121
  • 2
  • The naming conventions for such classes are no different than those of any other class. Use a name that is descriptive. If it's only going to be used in the product listing, call it something like `ProductDTO` – Robert Harvey Oct 13 '16 at 00:32

1 Answers1

2

When in doubt, use names that make a domain expert happy.

Let's take a trip into the future. You've now had a birthday. Taken a vacation. And coded up 5 more amazing things. Now your boss comes to you and says he needs vendor to show up on the index page. You've forgotten that page even exists let alone the code that produces it. So you search the code base for the phrase "IndexPage" hoping to get lucky.

What do you wish you'd named it now?

candied_orange
  • 102,279
  • 24
  • 197
  • 315