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. 如果相关对象尚未附加到对象上下文,则将相关对象设置为 Value 的 EntityReference<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. 两个对象都分离时,还可以通过将相关对象设置为 Value 的 EntityReference<TEntity> 属性或对 Add 调用 EntityCollection<TEntity> 方法,然后附加对象图中的根对象来定义关系。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.