2012-03-01 18 views
6

I generowane podmioty z CRM tak:CRM Odzyskaj podmiot - BŁĄD: Nie można rzutować obiektu typu 'Microsoft.Xrm.Sdk.Entity' wpisz '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 

Dla serviceContextName Ustawiłem XrmServiceContext. chcę pobrać jakiś podmiot z CRM za pomocą następny kod:

var context = new XrmServiceContext(myorgserv); 
var marketingList = context.ListSet.Where(item => item.Id == new Guid("SOME GUID")); 

A ja dostaję błąd:

Message "Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'CRMEntities.List'." 

Po „dodaj do oglądania” Widziałem, że każdy zbiór jednostek w kontekście mieć ta sama wiadomość. Co przeoczyłem?

Odpowiedz

16

Problem rozwiązany. Po zainicjowaniu OrganizationServiceProxy, muszę zadzwonić pod numer Metoda 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(); 

Kluczową sprawą jest: orgserv.EnableProxyTypes();

+0

Dziękujemy! Waliłam głową o ścianę, działa idealnie! –

Powiązane problemy