检查实体元数据中的实体是否是虚拟的

问题描述 投票:0回答:1

我正在尝试获取 Dynamics 中所有实体及其行数的列表。我使用下面的代码。问题是第二次调用获取每个实体的行数时会抛出错误

Entity xxx is a virtual entity, which is not supported

var list = new List<MyEntityData>();

//make a request to get entities
var entityRequest = new RetrieveAllEntitiesRequest()
{
    EntityFilters = EntityFilters.Entity,
    RetrieveAsIfPublished = true
};

//call the request
var entityResponse = (RetrieveAllEntitiesResponse)Dynamics._service.Execute(entityRequest);

//make a request to get the entity row count
var request = new RetrieveTotalRecordCountRequest
{
    EntityNames = entityResponse.EntityMetadata.Where(x => x.CanCreateForms.Value == true)
                  .Select(x => x.LogicalName).ToArray()
};

//call the request
var response = (RetrieveTotalRecordCountResponse)Dynamics._service.Execute(request); //error here

//loop all the results to get the entity name with the row count
foreach (var item in response.EntityRecordCountCollection)
{
    list.Add(new MyEntityData()
    {
        name = item.Key,
        rows = (int)item.Value
    });
}

我尝试通过设置

entityResponse
RetrieveAsIfPublished = true
来过滤掉
.Where(x => x.CanCreateForms.Value == true)
中的实体,但是两者都不起作用,虚拟实体仍然存在。

那么有人知道如何从

entityResponse
中过滤掉虚拟实体吗?

c# dynamics-crm microsoft-dynamics
1个回答
0
投票

每个虚拟实体都包含不等于null的DataProvideId和DataSourceId。您可以尝试根据这些属性添加过滤器。祝你好运。

© www.soinside.com 2019 - 2024. All rights reserved.