共用方式為


RelationshipManager.InitializeRelatedCollection<TTargetEntity> 方法

定義

初始化使用無參數建構函式所建立的現有 EntityCollection<TEntity>

public:
generic <typename TTargetEntity>
 where TTargetEntity : class, System::Data::Objects::DataClasses::IEntityWithRelationships void InitializeRelatedCollection(System::String ^ relationshipName, System::String ^ targetRoleName, System::Data::Objects::DataClasses::EntityCollection<TTargetEntity> ^ entityCollection);
public:
generic <typename TTargetEntity>
 where TTargetEntity : class void InitializeRelatedCollection(System::String ^ relationshipName, System::String ^ targetRoleName, System::Data::Objects::DataClasses::EntityCollection<TTargetEntity> ^ entityCollection);
[System.ComponentModel.Browsable(false)]
public void InitializeRelatedCollection<TTargetEntity> (string relationshipName, string targetRoleName, System.Data.Objects.DataClasses.EntityCollection<TTargetEntity> entityCollection) where TTargetEntity : class, System.Data.Objects.DataClasses.IEntityWithRelationships;
[System.ComponentModel.Browsable(false)]
public void InitializeRelatedCollection<TTargetEntity> (string relationshipName, string targetRoleName, System.Data.Objects.DataClasses.EntityCollection<TTargetEntity> entityCollection) where TTargetEntity : class;
[<System.ComponentModel.Browsable(false)>]
member this.InitializeRelatedCollection : string * string * System.Data.Objects.DataClasses.EntityCollection<'argetEntity (requires 'argetEntity : null and 'argetEntity :> System.Data.Objects.DataClasses.IEntityWithRelationships)> -> unit (requires 'argetEntity : null and 'argetEntity :> System.Data.Objects.DataClasses.IEntityWithRelationships)
[<System.ComponentModel.Browsable(false)>]
member this.InitializeRelatedCollection : string * string * System.Data.Objects.DataClasses.EntityCollection<'argetEntity (requires 'argetEntity : null)> -> unit (requires 'argetEntity : null)
Public Sub InitializeRelatedCollection(Of TTargetEntity As {Class, IEntityWithRelationships}) (relationshipName As String, targetRoleName As String, entityCollection As EntityCollection(Of TTargetEntity))
Public Sub InitializeRelatedCollection(Of TTargetEntity As Class) (relationshipName As String, targetRoleName As String, entityCollection As EntityCollection(Of TTargetEntity))

類型參數

TTargetEntity

要初始化之 EntityCollection<TEntity> 的型別。

參數

relationshipName
String

關聯性名稱。

targetRoleName
String

相關端的角色名稱。

entityCollection
EntityCollection<TTargetEntity>

要初始化的 EntityCollection<TEntity>

屬性

例外狀況

當提供的 EntityCollection<TEntity> 已經初始化時。

-或-

當關聯性管理員已經附加至 ObjectContext 時。

-或-

當關聯性管理員已經包含具有這個名稱和目標角色的關聯性時。

備註

方法 InitializeRelatedCollection 會初始化使用無參數建構函式所建立的現有 EntityCollection<TEntity>EntityCollection<TEntity> 是使用提供的關聯性和目標角色名稱初始化的。

InitializeRelatedCollection 方法只會在還原序列化期間使用。

適用於