简体   繁体   中英

Dynamics CRM how to get list of all entities

Working with CRM 2013, how can I get a list of all entities in the CRM via the connectionManager class? I want to get all the entities for the current connection.

Thank you for your comment and answer it work now, this is my function

public static EntityMetadata[] GetEntities ( IOrganizationService organizationService)
{
    Dictionary<string, string> attributesData = new Dictionary<string, string>();
    RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest();
    RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse();
    metaDataRequest.EntityFilters = EntityFilters.Entity;

    // Execute the request.

    metaDataResponse = (RetrieveAllEntitiesResponse)organizationService.Execute(metaDataRequest);

    var entities = metaDataResponse.EntityMetadata;

    return entities;
}

and i call my function in the windows app form like this:

var allEntities = CRMHelpers.GetEntities(service);
foreach (EntityMetadata Entity in allEntities)
{
    cbxEntity.Items.Add(Entity.LogicalName);
}

If you are looking for getting the entity metadata using code (C#) then we have inbuilt messages to get all entities and if required attribute level information as well. You can use the message "RetrieveAllEntitiesRequest". A sample code would be as follows to achieve the same.

RetrieveAllEntitiesRequest retrieveAllEntityRequest = new RetrieveAllEntitiesRequest
{
    RetrieveAsIfPublished = true,
    EntityFilters = EntityFilters.Attributes
};
RetrieveAllEntitiesResponse retrieveAllEntityResponse = (RetrieveAllEntitiesResponse)serviceProxy.Execute(retrieveAllEntityRequest);

If you need to get a specific entity information then you may use the message "RetrieveEntityRequest". A sample for the same would be as follows,

RetrieveEntityRequest entityRequest = new RetrieveEntityRequest
{
    EntityFilters = EntityFilters.Attributes,
    LogicalName = entityName,
    RetrieveAsIfPublished = true
};
RetrieveEntityResponse entityResponse = (RetrieveEntityResponse)serviceProxy.Execute(entityRequest);

Hope this is what you were looking for. Let us know if you need any more information on the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM