RelatedEnd.Attach<TEntity>(IEnumerable<TEntity>, Boolean) 方法

定義

定義兩個所附加物件之間的關聯性。Defines a relationship between two attached objects.

protected public:
generic <typename TEntity>
 void Attach(System::Collections::Generic::IEnumerable<TEntity> ^ entities, bool allowCollection);
protected internal void Attach<TEntity> (System.Collections.Generic.IEnumerable<TEntity> entities, bool allowCollection);
member this.Attach : seq<'Entity> * bool -> unit
Protected Friend Sub Attach(Of TEntity) (entities As IEnumerable(Of TEntity), allowCollection As Boolean)

類型參數

TEntity

要附加之實體物件的 IEnumerable<T> 集合類型。The type of the IEnumerable<T> collection of entity objects to attach.

參數

entities
IEnumerable<TEntity>

實體物件的 IEnumerable<T> 集合。An IEnumerable<T> collection of entity objects.

allowCollection
Boolean

指定正在附加的物件是否屬於集合的一部分。Specifies whether the object being attached is part of a collection.

備註

Attach<TEntity>(IEnumerable<TEntity>, Boolean) 方法是用來在物件與相關物件已經附加至物件內容時,定義這兩個物件之間的關聯性。The Attach<TEntity>(IEnumerable<TEntity>, Boolean) method is used to define a relationship between an object and a related object when both objects are already attached to an object context. 如果相關物件尚未附加至物件內容,請將相關物件設定為 ValueEntityReference<TEntity> 屬性或針對 Add 呼叫 EntityCollection<TEntity> 方法。Set the related object to the Value property of the EntityReference<TEntity> or call the Add method on the EntityCollection<TEntity> if the related object is not already attached to the object context. 當這兩個物件都中斷連結時,您也可以透過將相關物件設定為 ValueEntityReference<TEntity> 屬性或針對 Add 呼叫 EntityCollection<TEntity> 方法,然後在物件圖形中附加根物件 (Root Object),定義其關聯性。When both objects are detached, you can also define the relationship by setting the related object to the Value property of the EntityReference<TEntity> or by calling the Add method on the EntityCollection<TEntity> and then attaching the root object in the object graph. 如需詳細資訊,請參閱 附加和卸離物件For more information, see Attaching and Detaching Objects.

在附加作業期間,物件服務會針對相關端呼叫 Attach<TEntity>(IEnumerable<TEntity>, Boolean) 方法。The Attach<TEntity>(IEnumerable<TEntity>, Boolean) method is called by Object Services during attach operations against a related end.

適用於