DIGITALLNature / DigitallPower

DIGITALLPOWER - the dotnet tool for the PowerPlatform from DIGITALL. A swiss army knife for all ALM issues where PAC still has weaknesses.
Microsoft Public License
7 stars 0 forks source link

Generate ToNamedEntityReference Method for Early Bound Entity Classes #5

Closed SimonFindling closed 1 year ago

SimonFindling commented 1 year ago

It would be really cool if c# model generation could add a method to generated early bound entity classes that overwrites ToEntityReference or can be used instead of ToEntityReference to generate a EntityReference which has a filled Name attribute.

Sadly this can't be implemented as a generic extension method for Entity class, because PrimaryNameAttribute is only obtainable via entity metadata which would need an Request to be retrieved.

But in model generation we have this information available and could implement a constant Like:

public const string PrimaryEntityAttributeName = "name";

and an Method like:

public EntityReference ToNamedEntityReference() 
{
    var reference = ToEntityReference();
    reference.Name = GetAttributeValue<string>(PrimaryEntityAttributeName);
    return reference;
}

or completely override the ToEntityReference Method with our own implementation, but I am not sure if this has a negative impact, because the ToEntityReference Method is not virtual.

PepperPix commented 1 year ago

@SimonFindling I have implemented it this way. However, certain special entities (such as systemuserroles) do not have a name field.

I suggest not to implement the method for these entities. What do you say? #11