Search code examples
asp.netentity-frameworkdynamic-dataentity-framework-4

Dynamic Data - Make Friendly Column Names?


I've created a Dynamic Data project with an Entity Framework model. It works nicely. But, right now it shows all my database tables with the db column names - which aren't always the most friendly (e.g. address_line_1). How can I got about giving these more friendly column titles that will display to the end user?


Solution

  • You should use Metadata classes to add additional annotations:

    [MetadataType(typeof(MovieMetaData))]
    public partial class Movie
    {
    }
    
    
    public class MovieMetaData
    {
        [Required]
        public object Title { get; set; }
    
        [Required]
        [StringLength(5)]
        public object Director { get; set; }
    
    
        [DisplayName("Date Released")]
        [Required]
        public object DateReleased { get; set; }
    }
    

    http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs - find Using Data Annotation Validators with the Entity Framework

    Attributes are used not only for setting display name, but also for validation, turning visibility, order or how data should be presented. You should look into it if you want to use Dynamic Data Entities project.