6

次のように 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'."

「ウォッチに追加」した後、コンテキスト内のエンティティのすべてのセットに同じメッセージがあることがわかりました。私は何を逃したのですか?

4

1 に答える 1

16

問題が解決しました。OrganizationServiceProxyを初期化した後、 EnableProxyTypesメソッドを呼び出す 必要があります。

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(); です。

于 2012-03-02T12:16:43.317 に答える