none
怎样获取自定义实体名字的集合? RRS feed

答案

  •  

    你可以通过MetadataService来获取所有实体的集合,然后判断那些是客户化的。
    // Create an authentication token.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    token.OrganizationName = "AdventureWorksCycle";

    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for AD Authentication.
    token.AuthenticationType = 0;

    // Create the metadata Web service;
    MetadataService service = new MetadataService();
    service.Url = "http://<servername>:<port>/MSCRMServices/2007/MetadataService.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    service.PreAuthenticate = true;


    // Create the request
    RetrieveAllEntitiesRequest allEntitiesRequest = new RetrieveAllEntitiesRequest();
    // Retrieve only the currently published changes, ignoring the changes that have
    // not been published.
    allEntitiesRequest.RetrieveAsIfPublished = false;
    allEntitiesRequest.MetadataItems = MetadataItems.EntitiesOnly;
            
    // Execute the request
    RetrieveAllEntitiesResponse allEntitiesResponse = (RetrieveAllEntitiesResponse)metadataService.Execute(allEntitiesRequest);
            
    // Iterate through the retrieved entities
    foreach (EntityMetadata entity in allEntitiesResponse.CrmMetadata)
    {
       if(entity.IsCustomEntity)
       {
           //客户化实体
       }
    }

    2008年10月6日 4:03
    版主