RelationshipManager Classe
Definição
Usado para acompanhar as relações entre objetos no contexto de objeto.Used to track relationships between objects in the object context.
public ref class RelationshipManager
[System.Serializable]
public class RelationshipManager
[<System.Serializable>]
type RelationshipManager = class
Public Class RelationshipManager
- Herança
-
RelationshipManager
- Atributos
Exemplos
O exemplo neste tópico é baseado no Microsoft SQL Server exemplos de produto: banco de dados.The example in this topic is based on the Microsoft SQL Server Product Samples: Database. O exemplo adiciona novas SalesOrderHeader entidades à Contact entidade.The example adds new SalesOrderHeader entities to the Contact entity. Em seguida, ele obtém todos os finais relacionados da Contact entidade e exibe o nome da relação, o nome da função de origem e o nome da função de destino para cada extremidade relacionada.Then it gets all related ends from the Contact entity and displays the relationship name, source role name, and target role name for each related end.
using (AdventureWorksEntities context =
new AdventureWorksEntities())
{
Contact contact = new Contact();
// Create a new SalesOrderHeader.
SalesOrderHeader newSalesOrder1 = new SalesOrderHeader();
// Add SalesOrderHeader to the Contact.
contact.SalesOrderHeaders.Add(newSalesOrder1);
// Create another SalesOrderHeader.
SalesOrderHeader newSalesOrder2 = new SalesOrderHeader();
// Add SalesOrderHeader to the Contact.
contact.SalesOrderHeaders.Add(newSalesOrder2);
// Get all related ends
IEnumerable<IRelatedEnd> relEnds =
((IEntityWithRelationships)contact).RelationshipManager
.GetAllRelatedEnds();
foreach (IRelatedEnd relEnd in relEnds)
{
Console.WriteLine("Relationship Name: {0}", relEnd.RelationshipName);
Console.WriteLine("Source Role Name: {0}", relEnd.SourceRoleName);
Console.WriteLine("Target Role Name: {0}", relEnd.TargetRoleName);
}
}
Using context As New AdventureWorksEntities()
Dim contact As New Contact()
' Create a new SalesOrderHeader.
Dim newSalesOrder1 As New SalesOrderHeader()
' Add SalesOrderHeader to the Contact.
contact.SalesOrderHeaders.Add(newSalesOrder1)
' Create another SalesOrderHeader.
Dim newSalesOrder2 As New SalesOrderHeader()
' Add SalesOrderHeader to the Contact.
contact.SalesOrderHeaders.Add(newSalesOrder2)
' Get all related ends
Dim relEnds As IEnumerable(Of IRelatedEnd) = DirectCast(contact, IEntityWithRelationships).RelationshipManager.GetAllRelatedEnds()
For Each relEnd As IRelatedEnd In relEnds
Console.WriteLine("Relationship Name: {0}", relEnd.RelationshipName)
Console.WriteLine("Source Role Name: {0}", relEnd.SourceRoleName)
Console.WriteLine("Target Role Name: {0}", relEnd.TargetRoleName)
Next
End Using
Comentários
RelationshipManager é usado para rastrear relações entre objetos em um contexto de objeto.RelationshipManager is used to track relationships between objects in an object context. Há uma instância da RelationshipManager classe para cada relação rastreada no contexto do objeto.There is one instance of the RelationshipManager class for each relationship tracked in the object context. As relações são definidas por associações em um modelo conceitual.Relationships are defined by associations in a conceptual model. Para obter mais informações, consulte Elemento de Associação (CSDL).For more information, see Association Element (CSDL).
Métodos
| Create(IEntityWithRelationships) |
Cria um novo objeto RelationshipManager.Creates a new RelationshipManager object. |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetAllRelatedEnds() |
Retorna uma enumeração de todas as extremidades relacionadas gerenciada pelo gerenciador de relacionamento.Returns an enumeration of all the related ends managed by the relationship manager. |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetRelatedCollection<TTargetEntity>(String, String) |
Obtém um EntityCollection<TEntity> de objetos relacionados com o nome da relação especificada e o nome da função de destino.Gets an EntityCollection<TEntity> of related objects with the specified relationship name and target role name. |
| GetRelatedEnd(String, String) |
Retorna um EntityCollection<TEntity> ou um EntityReference<TEntity> do tipo correto para a função de destino especificada em uma relação.Returns either an EntityCollection<TEntity> or EntityReference<TEntity> of the correct type for the specified target role in a relationship. |
| GetRelatedReference<TTargetEntity>(String, String) |
Obtém o EntityReference<TEntity> para um objeto relacionado usando a combinação especificada de nome da relação e o nome da função de destino.Gets the EntityReference<TEntity> for a related object by using the specified combination of relationship name and target role name. |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| InitializeRelatedCollection<TTargetEntity>(String, String, EntityCollection<TTargetEntity>) |
Inicializa uma EntityCollection<TEntity> existente que foi criada usando o construtor sem parâmetros.Initializes an existing EntityCollection<TEntity> that was created by using the parameterless constructor. |
| InitializeRelatedReference<TTargetEntity>(String, String, EntityReference<TTargetEntity>) |
Inicializa uma EntityReference<TEntity> existente que foi criada usando o construtor sem parâmetros.Initializes an existing EntityReference<TEntity> that was created by using the parameterless constructor. |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| OnDeserialized(StreamingContext) |
Usado internamente para desserializar objetos de entidade junto com instâncias do RelationshipManager.Used internally to deserialize entity objects along with the RelationshipManager instances. |
| OnSerializing(StreamingContext) |
Chamado pelo Serviços de Objeto para preparar um EntityKey para serialização binária com uma relação serializada.Called by Object Services to prepare an EntityKey for binary serialization with a serialized relationship. |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |