Using alias for link entity attributes in MS CRM

We can read link entity attributes by aliasing link entity or attributes. Here we will be discussing second point.

It is as simple as keeping alias attribute for each field with alias name. Here important note is , if you give alias name is same as filed or attribute name as shown below fetchXML, you don't need to type cast with "AliasedValue" to read this field. You can read the value direclty how you read parent attributes.




<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='new_workorder'>
       <attribute name='new_name' />
       <order attribute='new_name' descending='false' />
       <link-entity name='incident' from='incidentid' to='new_workorderid' visible='false' link-type='outer' alias='a'>
           <attribute name='new_incidentnumber' alias='new_incidentnumber' />
       </link-entity>
     </entity>
 </fetch>

Here you can read "new_incidentnumber" field with any type casting to AliasedValue.



string incidentNumber = Convert.ToString(entityCollection.Entities[0].Attributes["new_incidentnumber"]);
If you give alias name as different than field name then we should type cast with AliasedValue to read its value.










No comments:

Post a Comment

Featured Post

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more a...