CRM Recuperar entidade de Erro:Não é possível converter objeto do tipo 'Microsoft.Xrm.Sdk.A entidade' para o tipo 'CRMEntities.Lista'

StackOverflow https://stackoverflow.com/questions/9518994

Pergunta

Eu entidades geradas a partir de CRM como este:

CrmSvcUtil.exe /url:http://<servername>/<organizationname>/XRMServices/2011/Organization.svc
    /out:<outputfilename>.cs /username:<username> /password:<password> /domain:<domainname>
    /namespace:CRMEntities /serviceContextName:XrmServiceContext

Para serviceContextName Eu definida XrmServiceContext.Quero recuperar alguma entidade de CRM utilizando o seguinte código:

var context = new XrmServiceContext(myorgserv);
var marketingList = context.ListSet.Where(item => item.Id == new Guid("SOME GUID"));

E eu estou recebendo mensagem de erro:

Message "Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'CRMEntities.List'."

Depois de 'adicionar para assistir" eu vi que cada conjunto de entidades no contexto têm a mesma mensagem.O que foi que eu perdi?

Foi útil?

Solução

O problema foi resolvido.Depois de inicializar OrganizationServiceProxy, O que eu faço EnableProxyTypes o método.

OrganizationServiceProxy orgserv;
ClientCredentials clientCreds = new ClientCredentials();

    clientCreds.Windows.ClientCredential.UserName = username;
    clientCreds.Windows.ClientCredential.Password = password;
    clientCreds.Windows.ClientCredential.Domain = domain;
    IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(orgServiceUri);

    orgserv = new OrganizationServiceProxy(orgConfigInfo, clientCreds);
    orgserv.EnableProxyTypes();

Questão chave é: orgserv.EnableProxyTypes();

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top