EntityFrameworkCore.Generator icon indicating copy to clipboard operation
EntityFrameworkCore.Generator copied to clipboard

[Feature] Add 'Generate' option for the data-mapping

Open ArnaudB88 opened this issue 11 months ago • 4 comments

In our company, we use your generator for many years now with many developers. Over the years, we added some features so it works better with our solutions. As a sign of appreciation, I want to suggest some features because I think it will help some other developers as well.

Feature description: Add a 'generate' option for the mapping classes which indicates if the mappings should be generated or not.

YAML usage:

data:
  mapping:
    generate: true

Please review the feature request and evaluate if you think this is an addition to your repo. (pull request will be added)

Thanks

ArnaudB88 avatar Mar 22 '24 09:03 ArnaudB88

Why would you want to turn this off? The mapping is mostly required. Are you using attribute based mapping?

pwelter34 avatar Mar 22 '24 18:03 pwelter34

I can assume a dev generates an initial version of the entities and de mappings, afterwards makes changes to the mapping and wants to prevent these changes to be overridden when regenerating.

ArnaudB88 avatar Mar 26 '24 11:03 ArnaudB88

you can make changes anywhere outside the region, and it will be saved.

    public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder<Core.Data.Entities.Company> builder)
    {
        #region Generated Configure
        // table
        builder.ToTable("Company", "dbo");

        // key
        builder.HasKey(t => t.Id);

        // properties
        builder.Property(t => t.Id)
            .IsRequired()
            .HasColumnName("Id")
            .HasColumnType("int")
            .ValueGeneratedOnAdd();

        builder.Property(t => t.Name)
            .IsRequired()
            .HasColumnName("Name")
            .HasColumnType("nvarchar(100)")
            .HasMaxLength(100);

        #endregion
		
        // Safe to make changes here
    }

pwelter34 avatar Mar 26 '24 22:03 pwelter34

@pwelter34 if changes outside the generated region override the config above, it is indeed a solution. If you think there is no other valid scenario to ignore the mappings, you can close the issue.

ArnaudB88 avatar Mar 27 '24 07:03 ArnaudB88