Dynamic data - create friendly column names?

I created a Dynamic Data project with an Entity Framework model. It works beautifully. But now it shows all my database tables with db column names that are not always the friendliest (e.g. address_line_1). How can I get these friendlier column headers to be displayed to the end user?

+3
source share
4 answers

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 - Data Annotation Validator Entity Framework

, , , , . , Dynamic Data Entities.

+6

[DisplayName("A fancy column name")] 

.

Grz, Kris.

+1

VB.NET, .

:

<DisplayName("Name")> _
Public Property FirstName As Object

<DisplayName("Name")> _
Public FirstName As Object

,

+1

In order not to lose changes every time you update an object from the database, you need to create another class file outside the .cs files. For instance:

namespace ModelCustomers
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    [DisplayName("Table Name")]
    public partial class My_Class
    {
    }
}

Now, even if you update the object, you still have the changes from your own file.

0
source

Source: https://habr.com/ru/post/1750516/


All Articles