Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ArnaudB88 opened this issue Mar 22, 2024 · 4 comments · May be fixed by #544
Open

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

ArnaudB88 opened this issue Mar 22, 2024 · 4 comments · May be fixed by #544

Comments

@ArnaudB88
Copy link

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 pushed a commit to ArnaudB88/EntityFrameworkCore.Generator that referenced this issue Mar 22, 2024
@pwelter34
Copy link
Member

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

@ArnaudB88
Copy link
Author

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.

@pwelter34
Copy link
Member

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
    }

@ArnaudB88
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants