TrackableEntities / EntityFrameworkCore.Scaffolding.Handlebars

Scaffold EF Core models using Handlebars templates.
MIT License
208 stars 53 forks source link

Handlebars Transformers Issues #118

Closed codingdna2 closed 4 years ago

codingdna2 commented 4 years ago

This PR fix issue #98, includes all the fixes made by dmayhak and discussed in PR #102 including author requested changes, and completes it with some more fixes.

In order to reproduce the additional issues I've found, run the sample with the followings:

services.AddHandlebarsTransformers(
    entityNameTransformer: n => n == "CustomerSetting" ? "Setting" : n,
    entityFileNameTransformer: n => n,
    constructorTransformer: e => e.PropertyType == "CustomerSetting" ? new EntityPropertyInfo("Setting", e.PropertyName + "Foo") : e,
    propertyTransformer: e => e.PropertyName == "Setting" ? new EntityPropertyInfo(e.PropertyType, "Value") :
                                e.PropertyName == "Country" ? new EntityPropertyInfo("Country", e.PropertyName, false) : e,
    navPropertyTransformer: e => e.PropertyType == "CustomerSetting" ? new EntityPropertyInfo("Setting", e.PropertyName + "Foo") : e);

and execute the scaffold adding the DataAnnotation flag -d:

dotnet ef dbcontext scaffold "Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=NorthwindSlim; Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -o Models -c NorthwindSlimContext -f --context-dir Contexts -d

I wanted to add some unit tests because at the present moment Transformers are not covered, but I didn't find the time yet.

codingdna2 commented 4 years ago

@tonysneed These are the additional changes I made. I marked the PR as draft as I'm not really sure all the errors are covered. In detail, when I added parameter propertyType to TransformPropertyName and TransformNavPropertyName I couldn't check the passed value is correct everywhere. I guess the only way to approach it correctly would be creating some Unit Tests but I'm not sure I can find the time. Finally, I squashed just my modifications, leaving the @dmayhak one separated. I'm not sure is the correct way to credit him as I'm not a git expert (nor I know too much the PR etiquette)... You will have to pardon me on this ;)

tonysneed commented 4 years ago

@codingdna2 For now it's enough to test the transformers with the ScaffoldingSample project. Great job on finishing up the PR and crediting @dmayhak.