Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Power Tools Template Condition #11585


User avatar
0
mittera created

In power tools when an entity has more than one navigation property pointing to the same entity it uses the "Duplication Number" to uniquely identify the property.

This part is working as expected, but during the generation of the module.ts it lists the lookup module for each property, creating duplicate import and module decatenations.

I have tried to fix this in my template and have it some what working, but I am having trouble with the condition.

I am trying to target only the first lookup for each entity using the duplication number of 0 using the condition below

"condition": "{{NP_Duplication_Number_Here}} == X",

For "X" I have tried various values from '', "", 0, <1 but none of these work. (Even the escaped versions)

If I use the value of 2 and have enough properties defined it does target the second property, and no duplicates are generated.

How do I target the 0 or blank with a condition?

Below is a sample of the NavigationPropertyTemplates


6 Answer(s)
  • User Avatar
    0
    mittera created

    I found a solution.

    The issue was the {{NP_Duplication_Number_Here}} doesn't return '' or 0 as would be expected.

    If multiple navigation properties to the same entity are mapped on a new entity, the first one will not return anything if targeting {{NP_Duplication_Number_Here}} in a condition.

    All subsequent navigation properties linked to the same entity will return their index (2,3,4,ect...) for {{NP_Duplication_Number_Here}}.

    So the trick was to wrap the {{NP_Duplication_Number_Here}} in single quotes like this '{{NP_Duplication_Number_Here}}' this way when it is blank it still returns blank...

    My final template condition used for both navigation properties in FileTemplates\Client\Angular\ModuleTemplate\partialtemplates.txt:

    "condition": " '{{NP_Duplication_Number_Here}}' == '' "

    Now duplicate import and declarations are no longer being produced via generation.

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hello @mittera,

    Would it be possible for you to share your entity.json file with me so that I can test it on my computer? Additionally, based on my understanding, the issue appears within the module.ts file. Could you kindly provide the template or guidance on how to fix this problem using Power Tools?

  • User Avatar
    0
    mittera created

    What I ended up doing was as follows:

    1. Open the following folder in windows explorer: %SOLUTION_PATH%\AspNetZeroRadTool\FileTemplates\Client\Angular\ModuleTemplate

    2. Copy PartialTemplates.txt to PartialTemplates.custom.txt

    3. Find the following two placeholders and add the condition below them.

    3.1) "placeholder": "{{Import_Lookup_Table_Here}}", "condition": "'{{NP_Duplication_Number_Here}}' == ''",

    3.2) "placeholder": "{{Declare_Lookup_Table_Here}}", "condition": "'{{NP_Duplication_Number_Here}}' == ''",

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thank you for your report, I have created an issue https://github.com/aspnetzero/aspnet-zero-core/issues/4867. We will work on this for the next version of AspNet Zero.

    Also thank you for sharing the solution.

  • User Avatar
    0
    mittera created

    Thank you that would be great!

    Just to pass along an Idea....

    What about switching from the optional use of the duplication number on navigation properties and master details to just always using the foreign key property name?

    The duplication number is a good idea, but is not working 100%, as multiple places where the duplication number should be appended to ensure multiple navigation or master detail properties are handled successfully via code generation. This is exhibited in the support request above, and I am also seeing the same thing with master detail pages. Also the duplication number is not intuitive or developer friendly as you need to remember what #2 is....

    So if you are going to have to fix this long term, why not make it more intuitive and extensible at the same time?

    The foreign property name solution simplifies the developer experience, and can be implemented in as many unique configurations as needed. As the foreign property name would be unique for each property added...

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @mittera,

    Thanks for your idea. We don't have any plans for this at the moment. We may consider making such an improvement in the future.