Let's say I created a few models via Entity Framework, and one of them is called Paper_Results. This is how the class might look:
public partial class Paper_Results
{
public string Color { get; set; }
public int Height { get; set; }
public int Width { get; set; }
}
I want to use this class like a domain model. Now let's say I create a class the derives from Paper_Results with an added interface
public class Construction_Paper : Paper_Results, IMeasurementType
{
[Required]
public (new?) string Color { get; set; }
[Required]
[Range(1, Int32.MaxValue, ErrorMessage = "Value should be greater than or equal to 1")]
public (new?) int Height { get; set; }
[Required]
[Range(1, Int32.MaxValue, ErrorMessage = "Value should be greater than or equal to 1")]
public (new?) int Width { get; set; }
public virtual string MeasurementType
{
get { return "inches"; }
}
}
Now when I create my ViewModel, I'll used the derived class instead:
public class Construction_Paper_ViewModel
{
Construction_Paper cp;
List<Construction_Paper> cpList;
string title;
public Construction_Paper_ViewModel()
{
title = "Construction Paper";
cp = new Construction_Paper();
cpList = new List<Construction_Paper>();
}
}
I know I should be using uint instead of int for non-negative integers, but I just wanted to add more data annotations to the code. What I'm asking is what is the best OOP technique to derive from Paper_Result class, so that I don't have to modify it at all. The reason is because if I create a new solution and/or project, I don't want to do any modifications to it when I auto-regenerate it using Entity Framework. Should I use shadowing? Or the new keyword in the derived class? Or do you guys have any other better ideas?
The auto-generated EF models do not contain 'virtual' in their methods, thus the reason why I brought up shadowing and the new keyword.