Question

When coding against the CRM SDK using late binding what is the difference between accessing attributes using the GetAttributeValue method and accessing the attributes directly on the Entity object?

I am still very new to .NET and c# so if it is a simple language/platform understanding issue then apologies but maybe that's why I can't find much on the difference.

Was it helpful?

Solution

entity["myattributename"] will throw an exception if you attempt to access an attribute that is not in the attribute collection of the entity. It will also return it as an object.

entity.GetAttributeValue<T> will return the default value of the type if not found, and will not throw an exception if it isn't in the attributes collection of the entity.

OTHER TIPS

The entity.GetAttributeValue<T> will return an IEnumerable object which can be used in LINQ expressions. This may greatly speed-up development time and reduce lines of code logic. Based on Daryl's response (good explaination here: ).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top