DataObjectFieldAttribute クラス
アセンブリ: System (system.dll 内)

<AttributeUsageAttribute(AttributeTargets.Property)> _ Public NotInheritable Class DataObjectFieldAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Property)] public sealed class DataObjectFieldAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property)] public ref class DataObjectFieldAttribute sealed : public Attribute

基になるデータのスキーマに関する情報を提供するには、DataObjectFieldAttribute 属性を使用します。ObjectDataSourceDesigner クラスなどのデザイン時のクラスは、デザイン時に DataObjectAttribute 属性を使用し、公開されたスキーマに基づいてプロパティを設定します。
DataObjectAttribute 属性でマークされたオブジェクトの Select メソッドで返されるデータ項目のオブジェクトのメンバに、DataObjectFieldAttribute 属性を適用します。次の例では、NorthwindData クラスが DataObjectAttribute 属性でマークされ、NorthwindEmployee オブジェクトが格納された IEnumerable オブジェクトが GetAllEmployees メソッドから返されます。NorthwindEmployee クラスのフィールドが DataObjectFieldAttribute 属性でマークされ、それらが、基になるデータ ソースのデータ フィールドを表していることを示します。

パブリックに公開されたプロパティに DataObjectFieldAttribute を適用し、プロパティに関連付けられたメタデータを識別する方法を次のコード例に示します。この例では、NorthwindEmployee 型で、EmployeeID、FirstName、および LastName の 3 つのデータのプロパティを公開します。DataObjectFieldAttribute 属性は 3 つすべてのプロパティに適用されますが、EmployeeID プロパティの属性だけが、これがデータ行の主キーであることを示します。
Public Class NorthwindEmployee Public Sub New() End Sub 'New Private _employeeID As Integer <DataObjectFieldAttribute(True, True, False)> _ Public Property EmployeeID() As Integer Get Return _employeeID End Get Set(ByVal value As Integer) _employeeID = value End Set End Property Private _firstName As String = String.Empty <DataObjectFieldAttribute(False, False, False)> _ Public Property FirstName() As String Get Return _firstName End Get Set(ByVal value As String) _firstName = value End Set End Property Private _lastName As String = String.Empty <DataObjectFieldAttribute(False, False, False)> _ Public Property LastName() As String Get Return _lastName End Get Set(ByVal value As String) _lastName = value End Set End Property End Class 'NorthwindEmployee
public class NorthwindEmployee { public NorthwindEmployee() { } private int _employeeID; [DataObjectFieldAttribute(true, true, false)] public int EmployeeID { get { return _employeeID; } set { _employeeID = value; } } private string _firstName = String.Empty; [DataObjectFieldAttribute(false, false, true)] public string FirstName { get { return _firstName; } set { _firstName = value; } } private string _lastName = String.Empty; [DataObjectFieldAttribute(false, false, true)] public string LastName { get { return _lastName; } set { _lastName = value; } } }

System.Attribute
System.ComponentModel.DataObjectFieldAttribute


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DataObjectFieldAttribute クラスのページへのリンク