public void AssociateRecords(Microsoft.Xrm.Sdk.EntityReference objectRef, Microsoft.Xrm.Sdk.Relationship relationName, params Microsoft.Xrm.Sdk.EntityReference[] entityReferences) { var collec = new EntityReferenceCollection(); collec.AddRange(entityReferences); AdminOrganizationService.Associate(objectRef.LogicalName, objectRef.Id, relationName, collec); }
public static EntityCollection RetrieveManyToManyRelationship(string currentEntityLogicalName , string otherEntityPrimaryIdAttribute , Microsoft.Xrm.Sdk.EntityReference otherEntityReference , string relationshipSchemaName , IOrganizationService organizationService ) { EntityCollection entityCollection = null; Microsoft.Xrm.Sdk.Relationship relationship = new Microsoft.Xrm.Sdk.Relationship(relationshipSchemaName); QueryExpression query = new QueryExpression(); query.EntityName = currentEntityLogicalName; query.ColumnSet = new ColumnSet(true); RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection(); relatedEntity.Add(relationship, query); RetrieveRequest request = new RetrieveRequest(); request.RelatedEntitiesQuery = relatedEntity; request.ColumnSet = new ColumnSet(otherEntityPrimaryIdAttribute); request.Target = otherEntityReference; RetrieveResponse response = (RetrieveResponse)organizationService.Execute(request); if (((DataCollection <Microsoft.Xrm.Sdk.Relationship, Microsoft.Xrm.Sdk.EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities)))).Contains(new Microsoft.Xrm.Sdk.Relationship(relationshipSchemaName)) && ((DataCollection <Microsoft.Xrm.Sdk.Relationship, Microsoft.Xrm.Sdk.EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities))))[new Microsoft.Xrm.Sdk.Relationship(relationshipSchemaName)].Entities.Any()) { DataCollection <Microsoft.Xrm.Sdk.Entity> results = ((DataCollection <Microsoft.Xrm.Sdk.Relationship, Microsoft.Xrm.Sdk.EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities))))[new Microsoft.Xrm.Sdk.Relationship(relationshipSchemaName)].Entities; if (results != null && results.Any()) { entityCollection = new EntityCollection(); entityCollection.Entities.AddRange(results); } } return(entityCollection); }
public void Disassociate(string entityName, Guid entityId, Microsoft.Xrm.Sdk.Relationship relationship, EntityReferenceCollection relatedEntities) { Execute(new DisassociateRequest { Target = new EntityReference(entityName, entityId), Relationship = relationship, RelatedEntities = relatedEntities }); }
public void Disassociate(string entityName, Guid entityId, Microsoft.Xrm.Sdk.Relationship relationship, EntityReferenceCollection relatedEntities) { _service.Disassociate(entityName, entityId, relationship, relatedEntities); }