组织服务方法

 

发布日期: 2016年11月

适用于: Dynamics CRM 2015

重要

某些指向此 SDK 中方法的链接无效。 您可以从此页访问 Web 服务方法的文档:IOrganizationService

IOrganizationService Web 服务提供一组方法,用于对系统和自定义实体以及对组织的元数据执行最常见的操作。 也可以使用 IOrganizationService.Execute 方法和相应消息来执行这些操作。

创建

使用 IOrganizationService.Create 方法可以创建支持 Create 消息的任何实体(包括自定义实体)的实例(记录)。

检索

使用 IOrganizationService.Retrieve 方法可以检索实体的实例(记录)。

RetrieveMultiple

使用 IOrganizationService.RetrieveMultiple 方法可以检索集合记录。 可以使用查询表达式或 Fetch XML 查询来指定查询。

更新

使用 IOrganizationService.Update 方法可以更新现有记录。

删除​​

使用 IOrganizationService.Delete 方法可以删除现有记录。

关联

使用 IOrganizationService.Associate 方法可以创建参与关系的两个记录之间的链接。

解除关联

使用 IOrganizationService.Disassociate 方法可以删除两个记录之间的链接。

执行

使用 IOrganizationService.Execute 方法可以执行消息。 这包括常见处理(如数据记录和元数据的创建和删除)或专用处理(如导入或检测重复项)。

示例

下面的代码演示如何通过强类型使用 CreateRetrieveUpdate 方法。


//Define the account for which we will add letters                
Account accountToCreate = new Account
{
    Name = "Example Account"
};

//Define the IDs of the related letters we will create
_letterIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };

//This acts as a container for each letter we create. Note that we haven't
//define the relationship between the letter and account yet.
EntityCollection relatedLettersToCreate = new EntityCollection
{
    EntityName = Letter.EntityLogicalName,
    Entities =
    {
        new Letter{Subject = "Letter 1", ActivityId = _letterIds[0]},
        new Letter{Subject = "Letter 2", ActivityId = _letterIds[1]},
        new Letter{Subject = "Letter 3", ActivityId = _letterIds[2]}
    }
};

//Creates the reference between which relationship between Letter and
//Account we would like to use.
Relationship letterRelationship = new Relationship("Account_Letters");

//Adds the letters to the account under the specified relationship
accountToCreate.RelatedEntities.Add(letterRelationship, relatedLettersToCreate);

//Passes the Account (which contains the letters)
_accountId = _service.Create(accountToCreate);

Console.WriteLine("An account and {0} letters were created.", _letterIds.Length);


//Now we run through many of the same steps as the above "Create" example
Account accountToUpdate = new Account
{
    Name = "Example Account - Updated",
    AccountId = _accountId
};

EntityCollection relatedLettersToUpdate = new EntityCollection
{
    EntityName = Letter.EntityLogicalName,
    Entities =
    {
        new Letter{Subject = "Letter 1 - Updated", ActivityId = _letterIds[0]},
        new Letter{Subject = "Letter 2 - Updated", ActivityId = _letterIds[1]},
        new Letter{Subject = "Letter 3 - Updated", ActivityId = _letterIds[2]}
    }
};

accountToUpdate.RelatedEntities.Add(letterRelationship, relatedLettersToUpdate);

//This will update the account as well as all of the related letters
_service.Update(accountToUpdate);
Console.WriteLine("An account and {0} letters were updated.", _letterIds.Length);

另请参阅

IOrganizationService
使用 IOrganizationService Web 服务读取和写入数据及元数据
将消息(请求和响应类)与 Execute 方法结合使用
使用 ExecuteMultiple 提高批量数据加载的性能
组织服务中的 xRM 消息
组织服务中的 CRM 消息
通过 Microsoft Dynamics CRM 2015 Web 服务对用户进行身份验证
示例:创建、检索、更新和删除记录(早期绑定)
示例:创建、检索、更新和删除(晚期绑定)

© 2017 Microsoft。 保留所有权利。 版权