分享方式:


IOrganizationService.Associate 方法

Creates a link between records.

命名空間: Microsoft.Xrm.Sdk
組件: Microsoft.Xrm.Sdk (在 Microsoft.Xrm.Sdk.dll 中)

語法

'宣告
<OperationContractAttribute> _
<FaultContractAttribute(GetType(OrganizationServiceFault))> _
Sub Associate ( _
    entityName As String, _
    entityId As Guid, _
    relationship As Relationship, _
    relatedEntities As EntityReferenceCollection _
)
[OperationContractAttribute] 
[FaultContractAttribute(typeof(OrganizationServiceFault))] 
void Associate (
    string entityName,
    Guid entityId,
    Relationship relationship,
    EntityReferenceCollection relatedEntities
)

參數

  • entityName
    Type: 字串. The logical name of the entity that is specified in the entityId parameter.
  • entityId
    Type: Guid. 記錄的識別碼 to which the related records are associated.
  • relationship
    Type: Relationship. The name of the relationship to be used to create the link.

範例

The following example shows how to use the Associate method to create an association or link between records. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface. You can find the complete sample in the sample code package in the folder SampleCode\CS\GeneralProgramming\LateBound\AssociateDisassociateDE.cs.

備註

Message Availability

不論呼叫端是連線至伺服器還是離線狀態,此訊息都會正常運作。

Privileges and Access Rights

To perform this action, the caller must have privileges on the entity that is specified in the entityName parameter and access rights on the record that is specified in the entityId parameter. For a list of the required privileges, see Associate Privileges.

Notes for Callers

This method creates multiple associations in one transaction between the record that is specified by the entityId parameter and each record in the relatedEntities parameter for the specified relationship in the relationship parameter.

For a one-to-many relationship, this method sets the ReferencingAttribute in the related record to the value of the entityId.

For a many-to-many relationship, this method creates a record in the intersect table for the relationship, which contains the ID of both the referenced and referencing records. The intersect table name is defined in the IntersectEntityName property for the relationship. You need this when you query for the records. However, you need the relationship name to set the Relationship property. This name is defined in the SchemaName property for the relationship.

For more information about the exceptions that can be thrown when this method is called, see Handle Exceptions in Your Code.

Supported Entities

You can use this method to associate any records that participate in a relationship, including records for custom entities.

執行緒安全

此類型的任何公用靜態 (Visual Basic 中的 Shared) 成員都具備執行緒安全。任何執行個體成員都不保證具備執行緒安全。

平台

Development Platforms

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Target Platforms

Windows Server 2008、Windows Server 2012、Windows 7

請參閱

參照

IOrganizationService 介面
IOrganizationService 成員
Microsoft.Xrm.Sdk 命名空間
Entity Metadata
AssociateRequest
AssociateResponse
Assign

其他資源

Customize Entity Relationship Metadata
Sample: Associate (Early Bound)
Handle Exceptions in Your Code
Troubleshooting and Error Handling

Send comments about this topic to Microsoft.
© 2015 Microsoft. All rights reserved.