2011-10-12 8 views
8

Sto utilizzando CRM 2011, e il tentativo di aggiornare l'ownerid di contatto utilizzando questo codice:Posso aggiornare l'ID proprietario di un contatto usando LINQ?

var crmContext = new CustomCrmContext(service); 

var contact = crmContext.Contact.FirstOrDefault(c=>c.Id == id); 
contact.OwnerId.Id= newOwnerId; 
crmContext.UpdateObject(contact); 
crmContext.SaveChanges(); 

non ottengo errori, tuttavia, l'ownerid non aggiorna nel database. Sono in grado di aggiornare altri attributi, ma mi chiedo se il OwnerId è speciale e devi utilizzare OrganizationRequest ("Assegna")? In tal caso, dove è documentato questo, quindi so quali altri attributi non posso aggiornare?

risposta

12

Il proprietario di un record non può essere modificato con un aggiornamento. Devi inviare un AssignRequest invece.

// Create the Request Object and Set the Request Object's Properties 
var request = new AssignRequest 
{ 
    Assignee = new EntityReference(SystemUser.EntityLogicalName, _newOwnerId), 
    Target = new EntityReference(Account.EntityLogicalName, _accountId) 
}; 


// Execute the Request 
_service.Execute(request); 
+0

Esiste un elenco di altre proprietà che richiedono un oggetto di richiesta specifico o il proprietario è l'unico? – Daryl

+1

Lo stato è un altro: credo che il CRM generi due classi per entità con il modello SetStateAccountRequest e SetStateAccountResponse. – glosrob

+1

Come al solito, nessun avviso da SDK quando questo fallisce. – Ryan

Problemi correlati