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 开发者_C百科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?
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.
you can put a
[DisplayName("A fancy column name")]
attribute above the column names in a partial class of the generated one.
Grz, Kris.
When we are working with VB.NET is important to set the value as PROPERTY.
Use:
<DisplayName("Name")> _
Public Property FirstName As Object
instead of
<DisplayName("Name")> _
Public FirstName As Object
If you won't do that, you'll receive an error message
In order not to loose changes every time you update the entity from database, you need to create another class file outside of the designer .cs files like this:
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 entity you still have the changes from your own file.
精彩评论