It makes no sense not to inherit the attribute .
Removing the [Required] attribute when overriding substantially violates the LSP .
If NotRequiredDerived is a subtype of RequiredBase , then objects of type RequiredBase can be replaced with objects of type NotRequiredDerived (i.e. an object of type RequiredBase can be replaced by any object of a subtype NotRequiredDerived ) without changing any desired properties of the program.
To express this with simple code:
var requiredPhoneNumber = new RequiredBase() { PhoneNumber = "123456789" }; HandleRequiredBaseObject(requiredPhoneNumber); //Works var optionalPhoneNumber = new NotRequiredDerived() { PhoneNumber = null }; HandleRequiredBaseObject(optionalPhoneNumber); //Fails
HandleRequiredBaseObject(RequiredBase obj) essentially assumes that PhoneNumber is required (as defined by the RequiredBase class); and he does not expect to receive a derivative that lacks this restriction! This will result in runtime exceptions.
The only way to not violate the LSP is to ensure that the [Required] constraint is not violated on derived classes; this means that it makes no sense to try to remove the [Required] annotation first.
I can come up with one theoretical case where the meaning of attribute inheritance does not make sense: if the attribute extends the range of valid parameters, but does not limit it.
Suppose we create a PositiveNumber class and an attribute that sets it as well to resolve negative numbers:
public class Base { [NegativesAllowed] public PositiveNumber Number { get; set; } } public class Derived : Base { public PositiveNumber Number { get; set; } }
If Base allows all numbers, and Derived allows only positive numbers, then this does not in fact violate the LSP.
However, this seems like a very strong situation. Using a limited type, which is then expanded with an attribute, is not something you are about to encounter.
In your case, you simply should not inherit one model from another.
The fact that different attributes are required is the main reason why you should not inherit these classes! They must work differently from each other, and therefore should not pretend that one is a derivation of the other.