CRMはエンティティを取得する - エラー:「Microsoft.xrm.SDK.Entity」型のオブジェクトをキャストできません。
-
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 私は 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