shashisadasivan / EDMXTrimmer

D365 Finance and operations EDMX trimmer
MIT License
21 stars 12 forks source link

Keep bound actions for entity #26

Closed szilardd closed 1 year ago

szilardd commented 1 year ago

I have a bound action on an entity, which I call like this:

_resources.MyEntity.FirstOrDefault().MyAction()

The action is generated like this in the EDMX

<Action Name="MyAction" IsBound="true">
  <Parameter Name="MyEntity" Type="Microsoft.Dynamics.DataEntities.MyEntity" />
</Action>

Is it possible to keep the entity in the EDMX along with all its bound actions? Currently if I run this, the entity is kept, but the actions are removed

dotnet EDMXTrimmer.dll --edmxfile="MyEDM.edmx" --entitiestokeep=MyEntity

Thanks

FH-Inway commented 1 year ago

Thanks for reporting. Curious behavior, because there is already logic in place to keep the actions along with the entity. Did you check if this only happens with your entity or also with standard entities?

szilardd commented 1 year ago

My EDMX is from a Microsoft D365 Finance and Operations system. I have limited knowledge of which one is a standard entity, I believe BalanceControl is?. It has an action:

<Action Name="LedgerBalanceControlEntityCOAFieldCustomLookup" IsBound="true">
        <Parameter Name="BalanceControl" Type="Collection(Microsoft.Dynamics.DataEntities.BalanceControl)" />
        <Parameter Name="_fields" Type="Collection(Edm.String)" />
        <ReturnType Type="Edm.String" />
        <Annotation Term="Microsoft.Dynamics.OData.Core.V1.FieldLookup" String="ChartOfAccounts" />
</Action>

If i run this:

dotnet EDMXTrimmer.dll --edmxfile="MyEDM.edmx" --entitiestokeep=BalanceControl

The BalanceControl entity is kept

...
<EntityType Name="BalanceControl">
        <Key>
          <PropertyRef Name="dataAreaId" />
          <PropertyRef Name="MainAccountId" />
          <PropertyRef Name="ChartOfAccounts" />
        </Key>
...
<EntityContainer Name="Resources">
        <EntitySet Name="BalanceControls" EntityType="Microsoft.Dynamics.DataEntities.BalanceControl">
          <NavigationPropertyBinding Path="LedgerBalanceControlMainAccountRole" Target="MainAccounts" />
        </EntitySet>
</EntityContainer>
...

But the action is not there anymore

FH-Inway commented 1 year ago

Thanks for the information, that allowed me to try to reproduce the issue.

Yes, BalanceControl is a standard entity of D365FO.

For me, when I run your command (note that I added an "s" at the end of the entity name "BalanceControl"; without it, the file does contain neither the entity nor the action; I assume that was just a typo), I get a file that contains the entity and the action. See the resulting file in https://gist.github.com/FH-Inway/ecbdf37099e0f7a3935a43728c1fb353

In case you are not already using it, could you try it with the latest version? https://github.com/shashisadasivan/EDMXTrimmer/releases/tag/0.2.1.20230702

szilardd commented 1 year ago

Thanks for the help. I can confirm that it works with version 0.2.1.

Not an issue, just something I noticed with the previous version that I used was that it is listing the entities that are being kept, so in case you specified an entity to keep and it wasn't being shown in the output, you knew that you had a typo

Entity definitions found:
BalanceControl
EDMX Saved to file: ...

with v0.2.1 the output is only this:

Trimmed EDMX saved to file: ...
FH-Inway commented 1 year ago

Thanks for the feedback.

Regarding the output: You are right, I'm changing around the output. Try the --verbose parameter, this should give you at least the number of entities kept. I will keep your feedback in mind and consider adding the list of kept entities back in, maybe with another parameter as the list can grow quite long depending on the parameters to keep/exclude entities.