DisplayColumnAttribute 类

定义

指定作为外键列显示在被引用表中的列。

public ref class DisplayColumnAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public class DisplayColumnAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)>]
type DisplayColumnAttribute = class
    inherit Attribute
Public Class DisplayColumnAttribute
Inherits Attribute
继承
DisplayColumnAttribute
属性

示例

下面的示例演示如何使用 DisplayColumnAttribute 特性。 此示例执行以下任务:

  • 为 Address 和 Customer 表实现元数据分部类,这些表是 CustomerAddress 表的父表。

  • DisplayColumnAttribute 属性应用于 Address 元数据分部类以指定以下内容:

    • 地址表中的 City 列 (父表) 显示为 CustomerAddress 子表中的外键列。

    • “地址”表中的“PostalCode”列 (父表) 用于对 CustomerAddress 子表中的“地址”选择框进行排序。

    • 排序顺序设置为升序。

该示例将 DisplayColumnAttribute 属性应用于 Customer 元数据分部类,以指定作为 CustomerAddress 表外键列显示的 LastName 列。

using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
using System.Globalization;

[DisplayColumn("City", "PostalCode", false)]
public partial class Address
{
}

[DisplayColumn("LastName")]
public partial class Customer
{
}
Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations
Imports System.Globalization

<DisplayColumn("City", "PostalCode", False)> _
Partial Public Class Address

End Class

<DisplayColumn("LastName")> _
Public Partial Class Customer

End Class

若要编译示例,需要满足以下条件:

  • Visual Studio 2010 或更高版本的任何版本。

  • AdventureWorksLT 示例数据库。 有关如何下载和安装SQL Server示例数据库的信息,请参阅Microsoft SQL Server产品示例:GitHub上的数据库。 请确保为正在运行的SQL Server版本安装正确的示例数据库版本。

  • 动态数据驱动网站。 这使你可以为数据库创建数据上下文,并创建包含要自定义的数据字段的类。 有关详细信息,请参阅 Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding

注解

当表中的列包含外键时,动态数据会从引用的表中推断该列的显示值。 默认情况下,使用类型为字符串 (或文本) 引用表的第一列。 通过此属性 DisplayColumnAttribute 可以更改此默认行为,并指定要用作外键字段列的不同父表列。

应用此属性时,必须遵循以下使用约束:

  • 该属性只能应用于类。

  • 属性可由派生类继承。

  • 该属性只能应用一次。

构造函数

DisplayColumnAttribute(String)

使用指定的列初始化 DisplayColumnAttribute 类的新实例。

DisplayColumnAttribute(String, String)

使用指定的显示列和排序列初始化 DisplayColumnAttribute 类的新实例。

DisplayColumnAttribute(String, String, Boolean)

使用指定的显示列以及指定的排序列和排序顺序初始化 DisplayColumnAttribute 类的新实例。

属性

DisplayColumn

获取要用作显示字段的列的名称。

SortColumn

获取用于排序的列的名称。

SortDescending

获取一个值,该值指示是按升序还是降序进行排序。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于