DisplayColumnAttribute Classe

Definição

Especifica a coluna que é exibida na tabela referida como uma coluna de chave estrangeira.Specifies the column that is displayed in the referred table as a foreign-key column.

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
Herança
DisplayColumnAttribute
Atributos

Exemplos

O exemplo a seguir mostra como usar o DisplayColumnAttribute atributo.The following example shows how to use the DisplayColumnAttribute attribute. O exemplo executa as seguintes tarefas:The example performs the following tasks:

  • Implementa classes parciais de metadados para as tabelas address e Customer, que são tabelas pai para a tabela CustomerAddress.Implements metadata partial classes for the Address and Customer tables, which are parent tables for the CustomerAddress table.

  • Aplica o DisplayColumnAttribute atributo à Address classe parcial de metadados para especificar o seguinte:Applies the DisplayColumnAttribute attribute to the Address metadata partial class to specify the following:

    • A coluna City da tabela Address (a tabela pai) é exibida como a coluna Foreign-Key na tabela filho CustomerAddress.The City column from the Address table (the parent table) is displayed as the foreign-key column in the CustomerAddress child table.

    • A coluna PostalCode da tabela de endereços (a tabela pai) é usada para classificar a caixa de seleção de endereço na tabela filho CustomerAddress.The PostalCode column from the Address table (the parent table) is used for sorting the Address selection box in the CustomerAddress child table.

    • A ordem de classificação é definida como crescente.The sort order is set to ascending.

O exemplo aplica o DisplayColumnAttribute atributo à Customer classe parcial de metadados para especificar que a coluna LastName é exibida como a coluna de chave estrangeira para a tabela CustomerAddress.The example applies the DisplayColumnAttribute attribute to the Customer metadata partial class to specify that the LastName column in displayed as the foreign-key column for the CustomerAddress table.

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

Para compilar o exemplo, você precisa do seguinte:To compile the example, you need the following:

  • Qualquer edição do Visual Studio 2010 ou posterior.Any edition of Visual Studio 2010 or later.

  • O banco de dados de exemplo AdventureWorksLT.The AdventureWorksLT sample database. Para obter informações sobre como baixar e instalar o SQL Server banco de dados de exemplo, consulte Microsoft SQL Server exemplos de produtos: banco de dados no github.For information about how to download and install the SQL Server sample database, see Microsoft SQL Server Product Samples: Database on GitHub. Certifique-se de instalar a versão correta do banco de dados de exemplo para a versão do SQL Server que você está executando.Make sure that you install the correct version of the sample database for the version of SQL Server that you are running.

  • Um site dinâmico controlado por dados.A dynamic data-driven Web site. Isso permite que você crie um contexto de dados para o Database e crie a classe que contém o campo de dados a ser personalizado.This enables you to create a data context for the database and to create the class that contains the data field to customize. Para obter mais informações, consulte Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding.For more information, see Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding.

Comentários

Quando uma coluna em uma tabela contém uma chave estrangeira, Dados Dinâmicos infere o valor de exibição para aquela coluna da tabela referenciada.When a column in a table contains a foreign key, Dynamic Data infers the display value for that column from the referenced table. Por padrão, a primeira coluna da tabela referenciada cujo tipo é String (ou text) é usado.By default, the first column of the referenced table whose type is string (or text) is used. O DisplayColumnAttribute atributo permite que você altere esse comportamento padrão e especifique uma coluna de tabela pai diferente para usar como a coluna para o campo de chave estrangeira.The DisplayColumnAttribute attribute enables you to change this default behavior and to specify a different parent table column to use as the column for the foreign key field.

Ao aplicar esse atributo, você deve aderir às seguintes restrições de uso:When you apply this attribute, you must adhere to the following usage constraints:

  • O atributo só pode ser aplicado a uma classe.The attribute can only be applied to a class.

  • O atributo pode ser herdado por classes derivadas.The attribute can be inherited by derived classes.

  • O atributo pode ser aplicado somente uma vez.The attribute can be applied only one time.

Construtores

DisplayColumnAttribute(String)

Inicializa uma nova instância da classe DisplayColumnAttribute, usando a coluna especificada.Initializes a new instance of the DisplayColumnAttribute class by using the specified column.

DisplayColumnAttribute(String, String)

Inicializa uma nova instância da classe DisplayColumnAttribute usando as colunas de classificação e de exibição especificadas.Initializes a new instance of the DisplayColumnAttribute class by using the specified display and sort columns.

DisplayColumnAttribute(String, String, Boolean)

Inicializa uma nova instância da classe DisplayColumnAttribute usando a coluna de exibição, a coluna de classificação e a ordem de classificação especificadas.Initializes a new instance of the DisplayColumnAttribute class by using the specified display column, and the specified sort column and sort order.

Propriedades

DisplayColumn

Obtém o nome da coluna a ser usado como o campo de exibição.Gets the name of the column to use as the display field.

SortColumn

Obtém o nome da coluna a ser usada para classificação.Gets the name of the column to use for sorting.

SortDescending

Obtém um valor que indica se deve classificar em ordem crescente ou decrescente.Gets a value that indicates whether to sort in descending or ascending order.

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.When implemented in a derived class, gets a unique identifier for this Attribute.

(Herdado de Attribute)

Métodos

Equals(Object)

Retorna um valor que indica se essa instância é igual a um objeto especificado.Returns a value that indicates whether this instance is equal to a specified object.

(Herdado de Attribute)
GetHashCode()

Retorna o código hash para a instância.Returns the hash code for this instance.

(Herdado de Attribute)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Herdado de Attribute)
Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Implantações explícitas de interface

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.Maps a set of names to a corresponding set of dispatch identifiers.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.Retrieves the type information for an object, which can be used to get the type information for an interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.Provides access to properties and methods exposed by an object.

(Herdado de Attribute)

Aplica-se a