DataObjectFieldAttribute 类
定义
为表示数据字段的属性提供元数据。Provides metadata for a property representing a data field. 此类不能被继承。This class cannot be inherited.
public ref class DataObjectFieldAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class DataObjectFieldAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type DataObjectFieldAttribute = class
inherit Attribute
Public NotInheritable Class DataObjectFieldAttribute
Inherits Attribute
- 继承
- 属性
示例
下面的代码示例演示如何将应用于 DataObjectFieldAttribute 公开的属性,以标识与属性关联的元数据。The following code example demonstrates how you can apply the DataObjectFieldAttribute to a publicly exposed property to identify metadata associated with the property. 在此示例中, NorthwindEmployee 类型公开了三个数据属性: EmployeeID 、 FirstName 和 LastName 。In this example the NorthwindEmployee type exposes three data properties: EmployeeID, FirstName, and LastName. DataObjectFieldAttribute特性应用于所有三个属性; 但是,只有 EmployeeID 属性特性指示它是数据行的主键。The DataObjectFieldAttribute attribute is applied to all three properties; however, only the EmployeeID property attribute indicates it is the primary key for the data row.
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; }
}
}
Public Class NorthwindEmployee
Public Sub New()
End Sub
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
注解
使用 DataObjectFieldAttribute 属性提供有关基础数据架构的信息。Use the DataObjectFieldAttribute attribute to provide information about the schema of the underlying data. 设计时类(如类)在 ObjectDataSourceDesigner DataObjectAttribute 设计时根据公开的架构使用属性设置属性。Design-time classes such as the ObjectDataSourceDesigner class use the DataObjectAttribute attribute to set properties at design-time based on the exposed schema.
将特性应用于 DataObjectFieldAttribute 由特性标记的对象的 Select 方法返回的数据项对象的成员 DataObjectAttribute 。You apply the DataObjectFieldAttribute attribute to members of the data item objects that are returned by the Select method of an object marked with the DataObjectAttribute attribute. 在下面的示例中, NorthwindData 类标记有 DataObjectAttribute 特性,并返回一个对象, IEnumerable 其中包含 NorthwindEmployee 方法中的对象 GetAllEmployees 。In the following example, the NorthwindData class is marked with the DataObjectAttribute attribute, and returns an IEnumerable object containing NorthwindEmployee objects from the GetAllEmployees method. 类中的字段 NorthwindEmployee 标记有 DataObjectFieldAttribute 属性,以指示它们表示基础数据源中的数据字段。Fields in the NorthwindEmployee class are marked with the DataObjectFieldAttribute attribute to indicate they represent data fields in the underlying data source.
有关使用特性的详细信息,请参阅 特性。For more information about using attributes, see Attributes.
构造函数
| DataObjectFieldAttribute(Boolean) |
初始化 DataObjectFieldAttribute 类的新实例,并指示该字段是否是数据行的主键。Initializes a new instance of the DataObjectFieldAttribute class and indicates whether the field is the primary key for the data row. |
| DataObjectFieldAttribute(Boolean, Boolean) |
初始化 DataObjectFieldAttribute 类的新实例,并指示该字段是否是数据行的主键,以及该字段是否是数据库标识字段。Initializes a new instance of the DataObjectFieldAttribute class and indicates whether the field is the primary key for the data row, and whether the field is a database identity field. |
| DataObjectFieldAttribute(Boolean, Boolean, Boolean) |
初始化 DataObjectFieldAttribute 类的新实例,并指示该字段是否是数据行的主键,该字段是否是数据库标识字段,以及该字段是否可以为空。Initializes a new instance of the DataObjectFieldAttribute class and indicates whether the field is the primary key for the data row, whether the field is a database identity field, and whether the field can be null. |
| DataObjectFieldAttribute(Boolean, Boolean, Boolean, Int32) |
初始化 DataObjectFieldAttribute 类的新实例,指示该字段是否是数据行的主键,该字段是否是数据库标识字段以及该字段是否可以为空,并设置该字段的长度。Initializes a new instance of the DataObjectFieldAttribute class and indicates whether the field is the primary key for the data row, whether it is a database identity field, and whether it can be null and sets the length of the field. |
属性
| IsIdentity |
获取一个值,该值指示某一属性是否表示基础数据中的标识字段。Gets a value indicating whether a property represents an identity field in the underlying data. |
| IsNullable |
获取一个值,该值指示某一属性表示的字段在基础数据存储区中是否可以为空。Gets a value indicating whether a property represents a field that can be null in the underlying data store. |
| Length |
获取属性的长度(以字节为单位)。Gets the length of the property in bytes. |
| PrimaryKey |
获取一个值,该值指示某一属性是否在基础数据的主键中。Gets a value indicating whether a property is in the primary key in the underlying data. |
| TypeId |
在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute. (继承自 Attribute) |
方法
| Equals(Object) |
返回一个值,该值指示此实例是否等于指定的对象。Returns a value indicating whether this instance is equal to a specified object. |
| GetHashCode() |
返回此实例的哈希代码。Returns the hash code for this instance. |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| IsDefaultAttribute() |
在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (继承自 Attribute) |
| Match(Object) |
当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (继承自 Attribute) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |
显式接口实现
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers. (继承自 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface. (继承自 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1). (继承自 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object. (继承自 Attribute) |