So there's not much here to "normalize" the database (really only the OrderItems
class and maybe the Table Meta class as well) but I'm relatively happy with it.
My only concern is the repeated Name
property in many of the tables but since it doesn't appear in all tables, it doesn't make sense to me to put it in the meta.
namespace Ortund.Store
{
// Used to avoid repetition of comment properties.
// This class won't be included in the DbSet
// I know the naming sucks
public class TableMeta
{
public int Id { get; set; }
}
public class Category : TableMeta
{
public string Name { get; set; }
}
public class Subcategory : TableMeta
{
public Category Category { get; set; }
public string Name { get; set; }
}
public class Order : TableMeta
{
public string Number { get; set; } // I'd have called it OrderNumber but that seemed redundant
public User User { get; set; }
public List<OrderItem> Items { get; set; }
public decimal Total { get; set; }
public bool Paid { get; set; }
public bool Delivered { get; set; }
}
public class OrderItem : TableMeta
{
public Order Order { get; set; }
public Product Product { get; set; }
}
public class Product : TableMeta
{
public Subcategory Category { get; set; } // naming might be confusing?
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public decimal Discount { get; set; }
public bool Active { get; set; }
}
// would use ASP.NET Identity but all the blog posts I've found about
// how to use it are out of date
public class User : TableMeta
{
public string EmailAddress { get; set; }
public string Password { get; set; } // bcrypt secured
public string Token { get; set; } // bcrypt secured - used to reset password
}
public class Wishlist : TableMeta
{
public User User { get; set; }
public Product Product { get; set; }
}
}
1 Answer 1
Well, this is not particularly a bad idea (or maybe it is?) but it isn't a good one either.
You make the models more complex just to save one or two properties. Those are just simple data models so leave them simple.
An abstraction like the TableMeta
should have a purpose so you can use it for something meaningful like dependency injection but can you? No, you cannot. TableMeta
on its own does not mean anything and is completely useless - even as a raw data model.
Id
. \$\endgroup\$