简体   繁体   中英

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

Given the following simple CRM SDK code:

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) 

}

Why does IsLogical of the AccountId attribute (infact all attributes) not include a value (eg is always null)

在此处输入图片说明

My understanding here it should be True for AccountId as this is a logical attribute.

More info Im using the 2015 SDK Libraries from NUGET, and I am connecting to a 2013 instance of CRM. Could this be the incompatibility, Am I using the right libraries?

Many Thanks!

The purpose of the IsLogical attribute, as documented in the SDK, is for use in determining the sort-ability of a calculated field.

Per the SDK (link from BlueSam's answer):

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

If you are targeting a 2013 instance the value will be null. 2013 did not have calculated fields so it did not have a need for the IsLogical attribute.

If you are targeting a 2015 instance and looking at the IsLogical property for accountid the value will be true because accountid on the opportunity entity is a foreign key reference to the account entity.

The rule for calculated field is if the calculated field uses any field where IsLogical == true then the calculated field cannot be used for sorting.

It does NOT mean that the field is not editable on the UI, although it is true that many logical fields will not by editable on the UI it is not a rule per the SDK.

I modified your code to show IsLogical for all fields on the entity:

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);
}

It sounds like this doesn't apply to most attributes in the system. See this article . Here's an excerpt:

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.

Looks like IsLogical in the SDK has been introduced in 2015, and I'm using 2013 so its coming through as Null

They are still considered logical attributes in 2011/13 but they do not come back in the SDK.

If you are filtering attributes to keep out those which should not be edited, you should also look at the IsValidForUpdate property. This will tell you if the attribute is editable.

There are also attributes with AttributeType (or AttributeTypeName.Value) of 'Virtual' - these are never used so you can ignore them.

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