CRM检索实体 - 错误:无法缩小“Microsoft.xrm.sdk.entity”类型的对象键入“crentities.list”
-
14-11-2019 - |
题
我生成了如此:的CRM
CrmSvcUtil.exe /url:http://<servername>/<organizationname>/XRMServices/2011/Organization.svc
/out:<outputfilename>.cs /username:<username> /password:<password> /domain:<domainname>
/namespace:CRMEntities /serviceContextName:XrmServiceContext
.
对于 serviceContextName i set xrmserviceContext 。
我想使用下一个代码从CRM检索一些实体:
.
var context = new XrmServiceContext(myorgserv);
var marketingList = context.ListSet.Where(item => item.Id == new Guid("SOME GUID"));
,我收到错误:
.
Message "Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'CRMEntities.List'."
'添加到观看'后,我看到上下文中的每组实体都有相同的消息。 我错过了什么?
解决方案
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();
不隶属于 StackOverflow