Tag Archives: entity framework

Tips & Tricks: Extending your Entity Framework classes

There are different reasons why you would like to extend the existing properties on your entity framework classes, for instance when you want to add data validation attributes or the display attribute, commonly used in ASP.Net MVC to set the ‘display’ name of the property.

Here is how to do it without editing your auto generated Entity Framework (.edmx) file. ‘author’ is the entity framework class.

    public partial class author

    public class authorMetadata
        [Display(Name = "First name")]
        public string firstname { get; set; }

We further extend the original author class by adding another partial class and specify which class contains the metadata for the class using the Metadatatype attribute.