为什么 Dynamics CRM 2015 SDK RetrieveEntityRequest 没有在 AttributeMetadata 中返回 IsLogical?

Why is Dynamics CRM 2015 SDK RetrieveEntityRequest is not returning IsLogical in AttributeMetadata?

给定以下简单的 CRM SDK 代码:

using (var os = new OrganizationService(CrmConnection.Parse(".... some crm connection ..... "))
{
    var reReq = new RetrieveEntityRequest();
    reReq.EntityFilters = EntityFilters.All;
    reReq.RetrieveAsIfPublished = true;
    reReq.LogicalName = "opportunity";

    var reRes = os.Execute<RetrieveEntityResponse>(reReq);

    // null in my case?
    Console.WriteLine("AccountId: IsLogical = {0}", reRes.EntityMetadata.Attributes[0].IsLogical.Value) 

}

为什么 AccountId 属性(实际上是所有属性)的 IsLogical 不包含值(例如始终为空)

我的理解是 AccountId 应该是 True,因为这是一个逻辑属性。

更多信息 我正在使用 NUGET 的 2015 SDK 库,并且我正在连接到 CRM 的 2013 实例。这可能是不兼容,我使用的库是否正确?

非常感谢!

听起来这不适用于系统中的大多数属性。参见 this article。以下是摘录:

Logical attributes contain values which are stored in different database tables than other attributes in the entity. In most cases this internal implementation is not relevant to working with Microsoft Dynamics CRM.

看起来 SDK 中的 IsLogical 已于 2015 年引入,我使用的是 2013 年,因此它以 Null

的形式出现

它们在 2011/13 年仍被视为逻辑属性,但不会在 SDK 中回归。

如 SDK 中所述,IsLogical 属性的用途是用于确定计算字段的排序能力。

根据 SDK(link 来自 BlueSam 的回答):

When you use logical attributes as sources for a calculated field the values in the calculated field cannot be sorted.

如果您的目标是 2013 实例,则该值将为空。 2013 没有计算字段,因此不需要 IsLogical 属性。

如果您的目标是 2015 年实例并查看 accountidIsLogical 属性,则该值将为 true,因为 [= opportunity 实体上的 14=] 是对 account 实体的外键引用。

计算字段的规则是,如果计算字段使用了任何IsLogical == true的字段,则计算字段不能用于排序。

确实 NOT 意味着该字段在 UI 上不可编辑,尽管许多逻辑字段确实在 [=40] 上不可编辑=] 这不是每个 SDK 的规则。

我修改了您的代码以显示实体上所有字段的 IsLogical:

var reReq = new RetrieveEntityRequest();
reReq.EntityFilters = EntityFilters.All;
reReq.RetrieveAsIfPublished = true;
reReq.LogicalName = "opportunity";

var reRes = (RetrieveEntityResponse)conn.Execute(reReq);

foreach (var att in reRes.EntityMetadata.Attributes.OrderBy (a => a.LogicalName))
{
    Console.WriteLine("{0} IsLogical={1}",att.LogicalName, att.IsLogical.Value);
}

如果您过滤属性以排除不应编辑的属性,您还应该查看 IsValidForUpdate 属性。这将告诉您该属性是否可编辑。

还有一些属性的 AttributeType(或 AttributeTypeName.Value)为 'Virtual' - 这些属性从未使用过,因此您可以忽略它们。