CRM获取实体 - 错误:无法转换类型'Microsoft.Xrm.Sdk.Entity“对象键入'CRMEntities.List” [英] CRM Retrieve entity - Error: Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'CRMEntities.List'

查看:877
本文介绍了CRM获取实体 - 错误:无法转换类型'Microsoft.Xrm.Sdk.Entity“对象键入'CRMEntities.List”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我产生的实体从CRM这样的:

I generated entities from CRM like this:

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



对于 serviceContextName 我将 XrmServiceContext
我想用下面的代码检索CRM的一些实体:

For serviceContextName I set XrmServiceContext. I want to retrieve some entity from CRM using next code:

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'."

在添加观看我看到,在上下文中,每个实体的集合有相同的消息。
有什么我错过了吗?

After 'add to watch' I saw that every set of entities in context have the same message. What have I missed?

推荐答案

问题解决了。初始化后的 OrganizationServiceProxy ,我得叫
EnableProxyTypes 方式。

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



关键是: orgserv.EnableProxyTypes();

这篇关于CRM获取实体 - 错误:无法转换类型'Microsoft.Xrm.Sdk.Entity“对象键入'CRMEntities.List”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆