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.