asp.net-mvc Data annotations for Database first implementation (model code auto-generated)


Example

[MetadataType(typeof(RoleMetaData))]
public partial class ROLE
{
}

public class RoleMetaData
{
    [Display(Name = "Role")]
    public string ROLE_DESCRIPTION { get; set; }

    [Display(Name = "Username")]
    public string ROLE_USERNAME { get; set; }
}

If you used database-first and your model code was auto-generated, this message will appear above your model code:

This code was generated from a template. Manual changes to this file may cause unexpected behavior in your application. Manual changes to this file will be overwritten if the code is regenerated

If you want to use data-annotations and you don't want them to be over-written if you refresh the edmx just add another a partial class to your model folder that looks like the example above.