EntityReference<TEntity> クラス

定義

複数要素の接続性が 0 または 1 であるアソシエーションの関連 End を表します。

generic <typename TEntity>
 where TEntity : class, IEntityWithRelationshipspublic ref class EntityReference sealed : System::Data::Objects::DataClasses::EntityReference
generic <typename TEntity>
 where TEntity : classpublic ref class EntityReference sealed : System::Data::Objects::DataClasses::EntityReference
[System.Runtime.Serialization.DataContract]
[System.Serializable]
public sealed class EntityReference<TEntity> : System.Data.Objects.DataClasses.EntityReference where TEntity : class, IEntityWithRelationships
[System.Runtime.Serialization.DataContract]
[System.Serializable]
public sealed class EntityReference<TEntity> : System.Data.Objects.DataClasses.EntityReference where TEntity : class
[<System.Runtime.Serialization.DataContract>]
[<System.Serializable>]
type EntityReference<'Entity (requires 'Entity : null and 'Entity :> IEntityWithRelationships)> = class
    inherit EntityReference
[<System.Runtime.Serialization.DataContract>]
[<System.Serializable>]
type EntityReference<'Entity (requires 'Entity : null)> = class
    inherit EntityReference
Public NotInheritable Class EntityReference(Of TEntity)
Inherits EntityReference

型パラメーター

TEntity

参照のエンティティ型。

継承
EntityReference<TEntity>
属性

この例では、EntityReference<TEntity> オブジェクトを使用して、SalesOrderHeader オブジェクトと、関連付けられている注文の出荷先住所を表す Address オブジェクトとのリレーションシップを変更する方法を示します。


// Define the order and new address IDs.
int orderId = 43669;
int addressId = 26;

using (AdventureWorksEntities context
    = new AdventureWorksEntities())
{
    // Get the billing address to change to.
    Address address =
        context.Addresses.Single(c => c.AddressID == addressId);

    // Get the order being changed.
    SalesOrderHeader order =
        context.SalesOrderHeaders.Single(o => o.SalesOrderID == orderId);

    // You do not have to call the Load method to load the addresses for the order,
    // because  lazy loading is set to true
    // by the constructor of the AdventureWorksEntities object.
    // With  lazy loading set to true the related objects are loaded when
    // you access the navigation property. In this case Address.

    // Write the current billing street address.
    Console.WriteLine("Current street: "
        + order.Address.AddressLine1);

    // Change the billing address.
    if (!order.Address.Equals(address))
    {
        // Use Address navigation property to change the association.
        order.Address = address;

        // Write the changed billing street address.
        Console.WriteLine("Changed street: "
            + order.Address.AddressLine1);
    }

    // If the address change succeeds, save the changes.
    context.SaveChanges();

    // Write the current billing street address.
    Console.WriteLine("Current street: "
        + order.Address.AddressLine1);
}

注釈

EntityReference<TEntity> オブジェクトは、関連 End の複数要素の接続性が 0 または 1 の場合にナビゲーション プロパティによって返されます。 詳細については、「 NavigationProperty 要素 (CSDL)」を参照してください。

EntityReference<TEntity> オブジェクトには、リレーションシップの他方の End に、対応する EntityCollection<TEntity> (一対多のリレーションシップ) または EntityReference<TEntity> (一対一のリレーションシップ) がある場合があります。 EntityReference<TEntity>EntityCollection<TEntity> が同じリレーションシップの両 End をモデル化している場合、そのリレーションシップの整合性がオブジェクト レベルで維持されます。

このクラスは継承できません。

コンストラクター

EntityReference<TEntity>()

EntityReference<TEntity> の新しいインスタンスを作成します。

プロパティ

EntityKey

関連オブジェクトのキーを返します。

(継承元 EntityReference)
IsLoaded

すべての関連オブジェクトが読み込まれているかどうかを示す値を取得します。

(継承元 RelatedEnd)
RelationshipName

この関連 End が参加するリレーションシップの名前を取得します。

(継承元 RelatedEnd)
RelationshipSet

リレーション端のメタデータへの参照を取得します。

(継承元 RelatedEnd)
SourceRoleName

リレーションシップのソース End のロール名を取得します。

(継承元 RelatedEnd)
TargetRoleName

リレーションシップのターゲット端のロール名を取得します。

(継承元 RelatedEnd)
Value

この EntityReference<TEntity> によって返される関連オブジェクトを取得または設定します。

メソッド

Attach(TEntity)

オブジェクト コンテキストで 2 つのオブジェクト間の多対一または一対一のリレーションシップを作成します。

Attach<TEntity>(IEnumerable<TEntity>, Boolean)

アタッチされた 2 つのオブジェクト間のリレーションシップを定義します。

(継承元 RelatedEnd)
CreateSourceQuery()

関連オブジェクトを返す同等のオブジェクト クエリを作成します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEnumerator()

関連オブジェクトのコレクションを反復処理する IEnumerator を返します。

(継承元 RelatedEnd)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
Load()

派生クラスでオーバーライドされた場合、既定のマージ オプションを使用して関連 End に関連オブジェクトを読み込みます。

(継承元 RelatedEnd)
Load(MergeOption)

指定されたマージ オプションを使用してこの EntityReference<TEntity> の関連オブジェクトを読み込みます。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
Merge<TEntity>(IEnumerable<TEntity>, MergeOption, Boolean)

関連エンティティをローカルの EntityCollection<TEntity> にマージします。

(継承元 RelatedEnd)
OnDeserialized(StreamingContext)

RelationshipManager インスタンスと共にエンティティ オブジェクトを逆シリアル化する目的で内部的に使用されます。

(継承元 RelatedEnd)
OnRefDeserialized(StreamingContext)

このメソッドは、関連エンティティ オブジェクトをシリアル化する目的で内部的に使用されます。

OnSerializing(StreamingContext)

このメソッドは、関連エンティティ オブジェクトをシリアル化する目的で内部的に使用されます。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
ValidateEntityForAttach<TEntity>(TEntity, Int32, Boolean)

オブジェクトをローカル コレクションやローカル参照にアタッチできるかどうかを調べます。

(継承元 RelatedEnd)
ValidateLoad<TEntity>(MergeOption, String)

ローカル コレクションやローカル参照に関連オブジェクトを正しく読み込めるかどうかを確認します。

(継承元 RelatedEnd)
ValidateOwnerForAttach()

関連 End が属しているオブジェクトでアタッチ操作がサポートされているかどうかを確認します。

(継承元 RelatedEnd)

イベント

AssociationChanged

関連 End に変更が加えられた場合に発生します。

(継承元 RelatedEnd)

明示的なインターフェイスの実装

IRelatedEnd.Add(IEntityWithRelationships)

関連 End にオブジェクトを追加します。

(継承元 RelatedEnd)
IRelatedEnd.Add(Object)

関連 End にオブジェクトを追加します。

(継承元 RelatedEnd)
IRelatedEnd.Attach(IEntityWithRelationships)

関連 End でオブジェクトをアタッチします。

(継承元 RelatedEnd)
IRelatedEnd.Attach(Object)

リレーション端にオブジェクトをアタッチします。

(継承元 RelatedEnd)
IRelatedEnd.CreateSourceQuery()

関連 End に属するオブジェクトを表す IEnumerable を返します。

(継承元 RelatedEnd)
IRelatedEnd.Remove(IEntityWithRelationships)

関連 End のコレクションからオブジェクトを削除します。

(継承元 RelatedEnd)
IRelatedEnd.Remove(Object)

リレーション端に属しているオブジェクトをリレーション端から削除します。

(継承元 RelatedEnd)

適用対象