I just used PowerApps cli to generate (c#) Dataverse entities and one thing I don't understand is when an entity references another, the generated classes will have a property of the "EntityReference" type which will only have the name (field marked as display name), id and little more.
In a query expression where I link the two entities and then execute "RetrieveMultiple" I will never be able to get the fields of the linked entity. I either need to:
put an alias and column set in the link and then "swim" in the main entity attributes with "entity["."]
var query = new QueryExpression() { EntityName = Incident.EntityLogicalName, ColumnSet = new ColumnSet("casetypecode", "contactid", "createdon", "incidentid", "modifiedon", "prioritycode", "statuscode", "title") }; var queryMyEntityLink = query.AddLink(myEntity.EntityLogicalName, "myentityid", "myentityid", JoinOperator.LeftOuter); queryCountryChargerLink.Columns.AddColumns("field1","field2"); queryCountryChargerLink.EntityAlias = "myEntity";
Later in the code, to retrieve values I do
var dto = new IncidentDto()
{
Title = incidentEntity.Title,
...
};
if(incidentEntity.MyEntity != null)
{
dto.MyEntity = new MyEntity()
{
Field1 = (incidentEntity["myEntity.field1"] as AliasedValue)?.Value as string,
Field2 = (incidentEntity["myEntity.field2"] as AliasedValue)?.Value as string
};
}
- for each linked entity, execute yet another call via "Retrieve"
Are these really the only two ways?
To translate the result of "RetrieveMultiple" into an entity class I do:
_service.RetrieveMultiple(query)?.Entities?.Select(entity => entity.ToEntity<T>())
Note: I'm using "Micrsoft.PowerPlatform.Dataverse.Client" to access the dataverse and .net core 6.