本文整理汇总了C#中OrganizationServiceProxy.Disassociate方法的典型用法代码示例。如果您正苦于以下问题:C# OrganizationServiceProxy.Disassociate方法的具体用法?C# OrganizationServiceProxy.Disassociate怎么用?C# OrganizationServiceProxy.Disassociate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrganizationServiceProxy
的用法示例。
在下文中一共展示了OrganizationServiceProxy.Disassociate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// This method first connects to the Organization service. Afterwards, it
/// creates/retrieves a system user, and
/// updates the system user to associate with the salesperson role.
/// Note: Creating a user is only supported
/// in an on-premises/active directory environment.
/// </summary>
/// <param name="serverConfig">Contains server connection information.</param>
/// <param name="promptforDelete">When True, the user will be prompted to delete all
/// created entities.</param>
public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
{
try
{
//<snippetRemoveRoleFromUser1>
// Connect to the Organization service.
// The using statement assures that the service proxy is properly disposed.
using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials))
{
_serviceProxy.EnableProxyTypes();
CreateRequiredRecords();
// Retrieve a user.
SystemUser user = _serviceProxy.Retrieve(SystemUser.EntityLogicalName,
_userId, new ColumnSet(new String[] { "systemuserid", "firstname", "lastname" })).ToEntity<SystemUser>();
if (user != null)
{
Console.WriteLine("{1} {0} user account is retrieved.", user.FirstName, user.LastName);
// Find the role.
QueryExpression query = new QueryExpression
{
EntityName = "role",
ColumnSet = new ColumnSet("roleid"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "name",
Operator = ConditionOperator.Equal,
Values = {_givenRole}
}
}
}
};
// Get the role.
EntityCollection roles = _serviceProxy.RetrieveMultiple(query);
// Disassociate the role.
if (roles.Entities.Count > 0)
{
Role salesRole = _serviceProxy.RetrieveMultiple(query).Entities[0].ToEntity<Role>();
Console.WriteLine("Role {0} is retrieved.", _givenRole);
_serviceProxy.Disassociate(
"systemuser",
user.Id,
new Relationship("systemuserroles_association"),
new EntityReferenceCollection() { new EntityReference("role", salesRole.Id) });
Console.WriteLine("Role {0} is disassociated from user {1} {2}.", _givenRole, user.FirstName, user.LastName);
}
}
}
//</snippetRemoveRoleFromUser1>
}
// Catch any service fault exceptions that Microsoft Dynamics CRM throws.
catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
{
// You can handle an exception here or pass it back to the calling method.
throw;
}
}