2012-03-01 4 views
6

私はこのようなCRMからエンティティを生成:CRMエンティティを取得 - エラー:型 'Microsoft.Xrm.Sdk.Entity' のオブジェクトをキャストすることができませんを入力して 'CRMEntities.List'

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

を同じメッセージ。 私は何を欠席しましたか?

答えて

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

+0

ありがとうございました!私の頭を壁に叩いて、完璧に動作しました! –

関連する問題