Setting attributes of a property in partial classes / Is it possible to add an attribute to a property in a partial class?
Question I have an employee class generated by the Entity Framework (EF). public partial class employee { private string name; public string Name { get{return name;} set{ name = value;} } } Now I want to put a required attribute in the name property to use in for MVC3 validation in another employee partial class which is written by me in order to extend the one which is generated by EF so that I don't have to rewrite my code if I refresh the model generated by EF. My written partial class is in the same assembly and namespace. public partial class employee { // What should I write here to add required attribute in the Name property? } Answer It is actually possible only through buddy class but it is not recommended way. You should keep your validation in the custom view model because often you need different validations for different views but your entity can keep only a single set of validation attributes. Examp...