RelationshipManager 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
用於追蹤物件情境中物件間的關係。
public ref class RelationshipManager
[System.Serializable]
public class RelationshipManager
[<System.Serializable>]
type RelationshipManager = class
Public Class RelationshipManager
- 繼承
-
RelationshipManager
- 屬性
範例
此範例為 SalesOrderHeader 該實體新增實體 Contact 。 接著它會從實體取得所有相關端點 Contact ,並顯示每個相關端點的關聯名稱、來源角色名稱和目標角色名稱。
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);
}
}
備註
RelationshipManager 用於追蹤物件情境中物件間的關係。 每個在物件上下文中追蹤的關係,都有一個該類別的 RelationshipManager 實例。 關係是由概念模型中的關聯所定義。 欲了解更多資訊,請參閱關聯元素(CSDL)。