Metodi del servizio organizzazione

 

Data di pubblicazione: gennaio 2017

Si applica a: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

Il servizio Web IOrganizationService offre un set di metodi utilizzati per eseguire le operazioni più comuni nel sistema e nelle entità personalizzate e sui metadati dell'organizzazione. Queste operazioni possono essere eseguite tramite il metodo IOrganizationService.Execute e il messaggio corrispondente.

Crea

Utilizzare il metodo IOrganizationService.Create per creare un'altra istanza (record) per qualsiasi entità che supporti il messaggio Crea, incluse le entità personalizzate.

Recupero

Utilizzare il metodo IOrganizationService.Retrieve per recuperare un'istanza (record) di un'entità.

RetrieveMultiple

Utilizzare il metodo IOrganizationService.RetrieveMultiple per recuperare i record di una raccolta. La query può essere specificata mediante un'espressione di query o una query FetchXML.

Aggiorna

Utilizzare il metodo IOrganizationService.Update per aggiornare un record esistente.

Eliminazione

Utilizzare il metodo IOrganizationService.Delete per eliminare un record esistente.

Associata

Utilizzare il metodo IOrganizationService.Associate per creare un collegamento tra due record che fanno parte di una relazione.

Annulla associazione

Utilizzare il metodo IOrganizationService.Disassociate per eliminare il collegamento tra due record.

Esecuzione

Utilizzare il metodo IOrganizationService.Execute per eseguire un messaggio. Ciò comprende l'elaborazione comune come la creazione e l'eliminazione di record di dati e di metadati, oppure può trattarsi di un'elaborazione specifica, come ad esempio l'importazione o il rilevamento di duplicati.

Esempio

Il seguente codice indica come utilizzare i metodi Create, Retrieve e Update utilizzando i tipi complessi.


//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);

Vedere anche

IOrganizationService
Usa il Servizio organizzazione per leggere e scrivere dati o metadati.
Utilizzare i messaggi (classi di richiesta e di risposta) con il metodo Execute
Utilizzare ExecuteMultiple migliorare le prestazioni per il carico dei dati in blocco
Messaggi xRM nel servizio dell'organizzazione
Messaggi Dynamics 365 nel servizio dell'organizzazione
Autenticare gli utenti in Microsoft Dynamics 365
Esempio: creare, recuperare, aggiornare ed eliminare i record (associazione anticipata)
Esempio: creazione, recupero, aggiornamento ed eliminazione (associazione ritardata)

Microsoft Dynamics 365

© 2017 Microsoft. Tutti i diritti sono riservati. Copyright