Dynamics CRM how to get list of all entities

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.

Tags:

C#

Crm