MetadataTypeAttribute クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
データ モデル クラスに関連付けるメタデータ クラスを指定します。
public ref class MetadataTypeAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public sealed class MetadataTypeAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false)]
public sealed class MetadataTypeAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)>]
type MetadataTypeAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false)>]
type MetadataTypeAttribute = class
inherit Attribute
Public NotInheritable Class MetadataTypeAttribute
Inherits Attribute
- 継承
- 属性
例
次の例は、 MetadataTypeAttribute を使用してメタデータ クラスをエンティティ部分クラスに関連付ける方法を示しています。 この例では、 RequiredAttribute 属性をデータ フィールドに適用して、関連付けられているメタデータ クラスに追加情報を提供する方法を示します。
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
}
public class CustomerMetaData
{
// Apply RequiredAttribute
[Required(ErrorMessage = "Title is required.")]
public object Title;
}
Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations
<MetadataType(GetType(CustomerMetadata))> _
Partial Public Class Customer
End Class
Public Class CustomerMetadata
' Apply RequitedAttribute.
<Required(ErrorMessage:="Title is required.")> _
Public Title As Object
End Class
注釈
MetadataTypeAttribute属性を使用すると、クラスをデータ モデル部分クラスに関連付けることができます。 この関連付けられたクラスでは、データ モデルにない追加のメタデータ情報を指定します。
たとえば、関連付けられたクラスでは、 RequiredAttribute 属性をデータ フィールドに適用できます。 これにより、データベース スキーマでこの制約が必要ない場合でも、フィールドに値が指定されます。
MetadataTypeAttribute属性は次のように使用します。
アプリケーションで、変更するデータ モデル部分クラスを作成するファイルを作成します。
関連付けられているメタデータ クラスを作成します。
MetadataTypeAttribute属性を部分エンティティ クラスに適用し、関連付けられているクラスを指定します。
この属性を適用する場合は、次の使用上の制約に従う必要があります。
属性は、クラスにのみ適用できます。
属性は派生クラスによって継承できません。
属性は 1 回だけ適用できます。
コンストラクター
| 名前 | 説明 |
|---|---|
| MetadataTypeAttribute(Type) |
MetadataTypeAttribute クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| MetadataClassType |
データ モデル部分クラスに関連付けられているメタデータ クラスを取得します。 |
| 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) |