EntityReference<TEntity>.Attach(TEntity) Método
Definição
Cria uma relação muitos para um ou um para um entre dois objetos no contexto de objeto.Creates a many-to-one or one-to-one relationship between two objects in the object context.
public:
void Attach(TEntity entity);
public void Attach (TEntity entity);
override this.Attach : 'Entity -> unit
Public Sub Attach (entity As TEntity)
Parâmetros
- entity
- TEntity
O objeto que está sendo anexado.The object being attached.
Exceções
Quando o entity é null.When the entity is null.
Quando o entity não pode ser relacionado à extremidade relacionada atual.When the entity cannot be related to the current related end. Isso pode ocorrer quando a associação no esquema conceitual não dá suporte a uma relação entre os dois tipos.This can occur when the association in the conceptual schema does not support a relationship between the two types.
Comentários
O Attach método é usado para definir uma relação entre um objeto e um objeto relacionado quando ambos os objetos já estão anexados a um contexto de objeto.The Attach method is used to define a relationship between an object and a related object when both objects are already attached to an object context. Defina o objeto relacionado como a Value propriedade se o objeto relacionado ainda não estiver anexado ao contexto do objeto.Set the related object to the Value property if the related object is not already attached to the object context. Quando ambos os objetos são desanexados, você também pode definir a relação definindo o objeto relacionado como a Value propriedade e, em seguida, anexando o objeto raiz no grafo do objeto.When both objects are detached, you can also define the relationship by setting the related object to the Value property and then attaching the root object in the object graph. Para obter mais informações, consulte anexando e desanexando objetos.For more information, see Attaching and Detaching Objects.
O objeto associado a este EntityReference<TEntity> e a todos os objetos que estão sendo anexados a ele devem estar em um Unchanged Modified estado ou.The object associated with this EntityReference<TEntity> and all objects being attached to it must be in an Unchanged or Modified state.
Um objeto no Deleted estado só pode ser anexado quando o ObjectStateManager já está acompanhando a instância do relacionamento.An object in the Deleted state can only be attached when the ObjectStateManager is already tracking the relationship instance.