When you work with querying CDS tables you can come across a scenario where you need to join multiple tables using query expression or fetchXml.
- Using Query Expressions
- Using Fetch XML
How we get Primary entity attribute value & Linked entity attribute value
consider "entity" is an Entity object for the below snippet.
- Primary entity attribute
2. Primary entity attribute
entity.GetAttributeValue<AliasedValue>(attributeName).Value
Now how about having an extension method which can handle getting both with of value without any code changes while getting values from the entity
The above snippet also checks whether the attribute is present or not, it can also save lines where we always check whether the attribute is present or not
Usage
- entity.GetEntityAttributeValue<string>(attributeName);
- entity.GetEntityAttributeValue<int>(attributeName);
- entity.GetEntityAttributeValue<OptionSetValue>(attributeName)?.Value;
- entity.GetEntityAttributeValue<EntityReference>(attributeName)?.Id
- entity.GetEntityAttributeValue<Guid?>(attributeName)
- entity.GetEntityAttributeValue<Guid?>(attributeName)?.ToString()?? string.Empty;
- entity.GetEntityAttributeValue<int?>(attributeName);
Happy Coding!
1 Comments
Jack Galassini of the Alabama Council on Compulsive Gambling emphasized the adverse impact of compulsive playing and the resources throughout a presentation to the Clanton Kiwanis Club on Oct. 27. Another disadvantage of proxies is that may not|they could 우리카지노 not|they gained't} work with all playing web sites. That happens because of|as a end result of} some playing web sites can detect proxies and block them. The second types of proxies are residential and datacenter proxies.
ReplyDelete