views:

188

answers:

2

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?

+3  A: 

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.

LukLed
Thanks. You wouldn't happen to know where I could find something on this topic that is (a) not written for MVC and (b) is written in VB.NET?
davemackey
@davemackey: This is about validation: http://msdn.microsoft.com/en-us/library/cc668224.aspx
LukLed
@davemackey: This is about whole customization: http://msdn.microsoft.com/en-us/library/ee225428.aspx
LukLed
Maybe I'm just daft...but I've explored just about every page I can find on MSDN about the Entity Framework and have yet to find a working example in VB.NET of using something like DisplayName metadata.
davemackey
This appears to be a .Net 4.0 feature. My project is 3.5 so I cannot use this.
Mike at KBS
@Mike at KBS: DataAnnotations are surely not 4.0 feature.
LukLed
+1  A: 

Hi,

you can put a

[DisplayName("A fancy column name")] 

attribute above the column names in a partial class of the generated one.

Grz, Kris.

XIII