TableNameAttribute(String) 构造函数
定义
使用表的指定名称初始化 TableNameAttribute 类的新实例。Initializes a new instance of the TableNameAttribute class with the specified name for the table.
public:
TableNameAttribute(System::String ^ name);
public TableNameAttribute (string name);
new System.Web.DynamicData.TableNameAttribute : string -> System.Web.DynamicData.TableNameAttribute
Public Sub New (name As String)
参数
- name
- String
表将显示的名称。The name that the table will display.
示例
下面的示例演示如何设置表名称。The following example shows how to set the table name. 在此示例中,显示的表名称从 "ProductModelProductDescriptions" 更改为 "生产模型 Desc"。In the example, the displayed table name is changed from "ProductModelProductDescriptions" to "Prod Model Desc".
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.DynamicData;
[MetadataType(typeof(ProductModelProductDescriptionMetaData))]
//[TableName(""Prod Model Desc")]
[DisplayName("Prod Model Desc")]
public partial class ProductModelProductDescription {
}
public class ProductModelProductDescriptionMetaData {
[DisplayName("Modified")]
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
public object ModifiedDate { get; set; }
[DisplayName("Description")]
public object ProductDescription { get; set; }
}
Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations
Imports System.Web.DynamicData
'<TableName("Prod Model Desc")> _
<MetadataType(GetType(ProductModelProductDescriptionMetaData))> _
<DisplayName("Modified")> _
Public Class ProductModelProductDescription
End Class
Public Class ProductModelProductDescriptionMetaData
'<DisplayFormat(False, True, "{0:d}", True)> _
<DisplayName("Modified")> _
Public ReadOnly Property ModifiedDate() As Object
Get
Return ""
End Get
End Property
<DisplayName("Description")> _
Public ReadOnly Property ProductDescription() As Object
Get
Return ""
End Get
End Property
End Class
注解
TableNameAttribute当存在来自多个上下文的实体名称冲突时,特性用于更改元数据中的实体名称。The TableNameAttribute attribute is used to change the entity name in the metadata when there are entity name conflicts from multiple contexts. TableNameAttribute不应使用属性更改显示名称。The TableNameAttribute attribute should not be used to change the display name. 改 DisplayNameAttribute 为使用属性更改显示名称。Instead, use the DisplayNameAttribute attribute to change the display name.