EntityReference<TEntity> クラス

定義

0 または 1 の多重度を持つ関連付けの関連する終了を表します。

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);
}

注釈

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

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

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

コンストラクター

名前 説明
EntityReference<TEntity>()

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

プロパティ

名前 説明
EntityKey

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

(継承元 EntityReference)
IsLoaded

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

(継承元 RelatedEnd)
RelationshipName

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

(継承元 RelatedEnd)
RelationshipSet

関連する末尾のメタデータへの参照を取得します。

(継承元 RelatedEnd)
SourceRoleName

リレーションシップのソース末尾にあるロール名を取得します。

(継承元 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()

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

(継承元 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()

関連するエンドが属するオブジェクトがアタッチ操作をサポートしていることを確認します。

(継承元 RelatedEnd)

イベント

名前 説明
AssociationChanged

関連するエンドに変更が加えられたときに発生します。

(継承元 RelatedEnd)

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

名前 説明
IRelatedEnd.Add(IEntityWithRelationships)

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

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

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

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

関連する端にオブジェクトをアタッチします。

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

オブジェクトを関連する端にアタッチします。

(継承元 RelatedEnd)
IRelatedEnd.CreateSourceQuery()

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

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

関連する末尾にあるコレクションからオブジェクトを削除します。

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

オブジェクトが関連するエンドの一部である場合は、関連する末尾からオブジェクトを削除します。

(継承元 RelatedEnd)

適用対象