Base solution for your next web application
Open Closed

Using Power Tools Extension #11553


User avatar
0
maberry created

I have noticed several things with Power Tools that seem counterproductive to the mission of aspnetzero. Can someone please let me know if the issues listed below are problems with the extension or is it working as designed? If the latter, can someone please provide rationale? If I understand the thought process, I may be able to work differently so these situations are not a hinderance to my workflow.

  1. Power Tools generates code for the OnModelCreating section of the DbContext; however, the generated code seems to be lacking a lot of context compared to other similar code generators. Below are snippets of the same entity using Power Tools and then one using the ABP Commercial code generator.

Generated from Power Tools modelBuilder.Entity<Customer>(c => { c.HasIndex(e => new { e.TenantId }); });

Generated from ABP Suite builder.Entity<Customer>(b => { b.ToTable(mergeConsts.DbTablePrefix + "Customer", mergeConsts.DbSchema); b.ConfigureByConvention(); b.Property(x => x.TenantId).HasColumnName(nameof(Customer.TenantId)); b.Property(x => x.FirstName).HasColumnName(nameof(Customer.FirstName)).HasMaxLength(CustomerConsts.FirstNameMaxLength); b.Property(x => x.LastName).HasColumnName(nameof(Customer.LastName)).HasMaxLength(CustomerConsts.LastNameMaxLength); b.Property(x => x.Phone).HasColumnName(nameof(Customer.Phone)).HasMaxLength(CustomerConsts.PhoneMaxLength); b.Property(x => x.Email).HasColumnName(nameof(Customer.Email)).HasMaxLength(CustomerConsts.EmailMaxLength); b.Property(x => x.Business).HasColumnName(nameof(Customer.Business)).HasMaxLength(CustomerConsts.BusinessMaxLength); b.Property(x => x.FullName).HasColumnName(nameof(Customer.FullName)).HasMaxLength(CustomerConsts.FullNameMaxLength); b.Property(x => x.ContactType).HasColumnName(nameof(Customer.ContactType)); b.HasMany(x => x.Locations).WithOne().HasForeignKey(x => x.CustomerId).IsRequired().OnDelete(DeleteBehavior.NoAction); });

  1. I often find code generated several times for the same entity in the OnModelCreating section of the DbContext. For example, say I use Power Tools to create two entities: City and State. Once both are created, I return to PowerTools via the Regenerate Entity tab and create navigational properties between City and State. Rather than update existing code, Power Tools generates another City entity within OnModelCreating. This happens every time I regenerate an entity. It does not seem to be causing any issues, but at least very least it is bloating my code.

  1. Can you please point me to a tutorial related to how I should modify entities without breaking my code. For example - I created an entity titled Location with properties for Street Address, City, State, and Zip code. Later I decided I wanted separate tables for City, State, and Zip Code. I returned to Power Tools via the Regenerate Entity tab and removed the properties for City, State, and Zip Code. Once completed, I rebuilt and refreshed with nswag, but the result was so many errors I had to scrap the application and resort to an earlier copy. I do not have screenshots to show because I deleted the files; however, it seemed as though Power Tools deleted the properties from the projectName.Core folder, but it did not delete anywhere else. I have had this happen several times, so I assume there is a specific way the extension wants me to do it.

11 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @maberry

    • When compared to ABP Suite, generated code in OnModelCreating works as designed. ABP Suite and also ABP Framework has a different approach here, that's why its generated code is different.
    • Duplicate of City entity in OnModelCreating is not what we expect. Could you share steps to reproduce this problem ?
    • Making modification on generated entities to move some fields to separate tables (like creating a City table instead of City field in Location entity) shouldn't be done using Power Tools. Power Tools is designed to be used mostly for first time usage. You can ofcourse make modifications for adding primary (text, int etc...) fields to existing entities. However, for moving a field to a new table, it would be better to make changes on the generated entity using Visual Studio.
  • User Avatar
    0
    maberry created

    Hi @maberry

    • When compared to ABP Suite, generated code in OnModelCreating works as designed. ABP Suite and also ABP Framework has a different approach here, that's why its generated code is different.
    • Duplicate of City entity in OnModelCreating is not what we expect. Could you share steps to reproduce this problem ?
    • Making modification on generated entities to move some fields to separate tables (like creating a City table instead of City field in Location entity) shouldn't be done using Power Tools. Power Tools is designed to be used mostly for first time usage. You can ofcourse make modifications for adding primary (text, int etc...) fields to existing entities. However, for moving a field to a new table, it would be better to make changes on the generated entity using Visual Studio.
    • I completely understand the approaches are different, but doesnt really answer the question of why Power Tools does not generate code OnModelCreating. ABP Suite is not the only code generator that puts more information in OnModelCreating. Not doing so causing all kinds of warnings in Visual Studio for null referrences, etc when building a project. Your answer indicates that it is working as expected. My question again - are you able to provide rationale for this behavior considering it causes errors and goes against convention?

    • Steps to reproduce duplication of entities in OnModelCreating - This happens EVERY time I regenerate an entity using Power Tools. That is the only step.

    • Am I understanding correctly that an appropriate use of Power Tools would be to regenerate entities for the purpose of adding fields, relationships, etc; however, removing fields, relationships, etc is not an appropriate use of the entension? If that is the case, it would seem like that information should most certainly be included in the documentation. I can not be the only person who wasted hours attempting to fix broken code after trying to remove a field. Just a thought.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    • AspNet Zero uses conventions for table and field names. Because of that, we don't use detailed fluent configuration in OnModelCreating. For example, if your table has a field named Name, database field will have the same name. ABP Suite explicitly uses HasColumnName but it is handled conventionally in AspNet Zero. By the way, IsRequired should be used in AspNet Zero as well for the required fields.
    • Thanks, we will try this.
    • Removing a field should actually work with Power Tools. If you still have the error about this, could you share it with us ?

    Thanks,

  • User Avatar
    0
    maberry created

    Do you have any insight? I shared the code with you five days ago.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @maberry

    We have sent you an email but didn't get a reply. Could you check your spam folder ?

    Thanks,

  • User Avatar
    0
    maberry created

    Hi @maberry

    We have sent you an email but didn't get a reply. Could you check your spam folder ?

    Thanks,

    Hi - Do you have an update? I replied to your email two weeks ago.

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hello @maberry,

    Our team is actively working on resolving it, and we are committed to resolving it as quickly as possible. We appreciate your patience and understanding.

  • User Avatar
    0
    maberry created

    Is it possible to get an update? I continue to have this issue.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @maberry

    Sorry for the delay, I think @m.aliozkaya reproduced the problem but it happens in a specific case and we are trying to solve the problem.

  • User Avatar
    0
    TradeMaster created

    Is it possible to get an update? I continue to have this issue.

    Dear Maberry we have the same issue which you had before, may I know if where able to resolve it?

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @TradeMaster,

    Could you share your Entity.json for review? And also If you explain the error itself and how to reproduce it, I can help you more easily.