What is the best way to develop my application with the following data scenario?
For simplicity, my model has a base table called Project with the standard common fields, ProjectId, Name, StartDate, Owner etc.
It has a one-to-one relation with other tables that maintain data for different project types, for example, ConstructionProject, FinanceProject, HolidayProject etc. Each of these tables are linked back to the base Project table via their primary key, ProjectId.
Should my classes be based on a base class Project and other classes inherit from this? Such as :
public class Project
{
public int ProjectId { get; set; }
public string Name { get; set; }
public DateTime StartDate { get; set; }
public string Owner { get; set; }
}
public class ConstructionProject : Project
{
public string Location { get; set; }
public string Contractor { get; set; }
}
Or should I have the other types of projects as their own class with a Project object? For example:
public class ConstructionProject
{
public Project Project { get; set; }
public string Location { get; set; }
public string Contractor { get; set; }
}
As a standard MVC project then I can have the controllers handle the crud operations for the second scenario above as such:
public ActionResult Update(Project project)
{
// update project object
}
public ActionResult Update(ConstructionProject constructionProject)
{
// update constructionProject object
// update project object
}
Not sure how the controllers would look handling inherited objects in the first scenario?
The project is a standard C# MVC project using Entity Framework. There could potentially be several linked tables for the different project types. So which option is the best practice and how would the controllers be modelled (if different to the way I propose?) Or is there a better way?
Thanks
Edit - just to add some more info - the base class can also exist on it's own rather than be just a base class, in other words, the Project table can have records that do not have related records in the other tables, if that helps?