web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM SDK - entity.id vs entity.logicalNameId

(0) ShareShare
ReportReport
Posted on by 280

When communication with CRM through the SDK one has two options when asking for the ID of an entity:

  • entity.Id
  • entity.entityLogicalNameId

My question is, what is the difference and which one to use in which scenario.

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi,

    Logically they are the same since the Id attribute is not a field in the database but the platform sets it using the the entityLogicalNameId field when retrieving Entity records.

    If you are using early bound types then the generated type sets both the Id field and the entityLogicalNameId. So setting account.Id sets both the Id the AccountId field, and setting the AccountId field sets both the AccountId and the ID:

    public System.Nullable<System.Guid> AccountId
    
    {
    
    get
    {
        return this.GetAttributeValue<System.Nullable<System.Guid>>("accountid");
    }
    set
    {
        this.OnPropertyChanging("AccountId");
        this.SetAttributeValue("accountid", value);
        if (value.HasValue)
        {
            base.Id = value.Value;
        }
        else
        {
            base.Id = System.Guid.Empty;
        }
            this.OnPropertyChanged("AccountId");
        }
    }
    
    public override System.Guid Id
    {
    get
    {
        return base.Id;
    }
    set
    {
        this.AccountId = value;
    }
    }

    When using Sdk operations such as Update the platform expects the Id attribute to be set since this is serialized outside of the Attributes collection so if you are not using Early Bound Types you *must* set the Id attribute because it will not be set for you if you set the AccountId attribute using account["accountid"]=<GUID>

    Hope this helps,

    Scott

  • bahramzy Profile Picture
    280 on at

    Hi Scott, thanks for your response.

    But are there any performace cosiderations when using e.g. account.Id or account.accountId.Id?

  • ScottDurow Profile Picture
    21 on at

    The difference in operations is negligible so I wouldn't worry about it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans