2012-03-01 32 views
6

tôi tạo ra các đơn vị từ CRM như thế này:CRM Lấy thực thể - Lỗi: Không thể bỏ đối tượng của loại 'Microsoft.Xrm.Sdk.Entity' gõ '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 

Đối serviceContextName Tôi đặt XrmServiceContext. Tôi muốn lấy một số tổ chức từ CRM sử dụng mã tiếp theo:

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

Và tôi nhận được lỗi:

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

Sau 'thêm để xem' Tôi thấy rằng tất cả các tập hợp các thực trong bối cảnh có cùng một thông điệp. Tôi đã bỏ lỡ điều gì?

Trả lời

16

Sự cố được giải quyết. Sau khi khởi tạo OrganizationServiceProxy, tôi phải gọi Phương thức 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(); 

Điều quan trọng là: orgserv.EnableProxyTypes();

+0

Cảm ơn bạn! Bị đập đầu vào tường, hoạt động hoàn hảo! –

Các vấn đề liên quan