使用CRM 2013,如何通过connectionManager
课程获取CRM中所有实体的列表?我希望所有当前连接的实体。
答案 0 :(得分:8)
感谢您的评论并立即回答, 这是我的功能
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;
}
我在Windows应用程序表单中调用我的函数,如下所示:
var allEntities = CRMHelpers.GetEntities(service);
foreach (EntityMetadata Entity in allEntities)
{
cbxEntity.Items.Add(Entity.LogicalName);
}
答案 1 :(得分:4)
如果您正在寻找使用代码(C#)获取实体元数据,那么我们有内置消息来获取所有实体以及必要的属性级别信息。您可以使用消息&#34; RetrieveAllEntitiesRequest&#34;。下面的示例代码如下所示。
RetrieveAllEntitiesRequest retrieveAllEntityRequest = new RetrieveAllEntitiesRequest
{
RetrieveAsIfPublished = true,
EntityFilters = EntityFilters.Attributes
};
RetrieveAllEntitiesResponse retrieveAllEntityResponse = (RetrieveAllEntitiesResponse)serviceProxy.Execute(retrieveAllEntityRequest);
如果您需要获取特定的实体信息,那么您可以使用消息&#34; RetrieveEntityRequest&#34;。相同的样本如下,
RetrieveEntityRequest entityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Attributes,
LogicalName = entityName,
RetrieveAsIfPublished = true
};
RetrieveEntityResponse entityResponse = (RetrieveEntityResponse)serviceProxy.Execute(entityRequest);
希望这就是你要找的东西。如果您需要更多相关信息,请告诉我们。