CRM Recupere la entidad - Error: no se puede colocar el objeto de tipo 'Microsoft.xrm.sdk.entity' para escribir 'Cremities.list'
-
14-11-2019 - |
Pregunta
He generado entidades de CRM así:
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 i establece xrmservicecontext .
Quiero recuperar alguna entidad de CRM usando el siguiente código:
var context = new XrmServiceContext(myorgserv);
var marketingList = context.ListSet.Where(item => item.Id == new Guid("SOME GUID"));
y estoy recibiendo error:
Message "Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'CRMEntities.List'."
Después de 'Añadir a ver' Vi que cada conjunto de entidades en contexto tiene el mismo mensaje. ¿Qué he perdido?
Solución
Problem solved. After initializing OrganizationServiceProxy, I have to call EnableProxyTypes method.
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();
Key thing is: orgserv.EnableProxyTypes();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow