Which ID property to use in early-binding programming in CRM?

Have you noticed that the generated early-binding classes always have 2 ID properties? For example, the Account class would have Id and AccountId. The Contact class would have Id and ContactId.

Which property should you use in early-binding programming?

Well, if you are writing a LINQ query, do not use the Id property, and use the AccountId property instead. Using the Id property in your LINQ query will result in an exception with the cryptic message “attributeName“. Digging a bit deeper, you will see that the underlying exception message is “System.ArgumentNullException: Value cannot be null.\r\nParameter name: attributeName.

While in the generated early-binding class both properties are tagged with the [Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute(“accountid”)] attribute, I could only get the LINQ query to work with AccountId. I suspect that the CRM LINQ parser does not look at this attribute when parsing the LINQ query.

Advertisements

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in CRM. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s