Skip to content

Conversation

@JohnGoldInc
Copy link
Contributor

Changes to Support Schema Foldering, And Nullable EF Core Project Using propertyTransformer: (epi) => new EntityFrameworkCore.Scaffolding.Handlebars.EntityPropertyInfo(epi.PropertyType + (epi.PropertyIsNullable == true && !epi.PropertyType.Contains("?") ? "?" :"") , epi.PropertyName, epi.PropertyIsNullable)

…ng propertyTransformer: (epi) => new EntityFrameworkCore.Scaffolding.Handlebars.EntityPropertyInfo(epi.PropertyType + (epi.PropertyIsNullable == true && !epi.PropertyType.Contains("?") ? "?" :"") , epi.PropertyName, epi.PropertyIsNullable)
@johngold-onshift
Copy link

@tonysneed Any feedback?

@tonysneed tonysneed added the enhancement New feature or request label Apr 18, 2020
@tonysneed
Copy link
Contributor

@johngold-onshift The way I think we want to approach adding support for nullable reference types is to add an EnableNullableReferenceTypes property to ReverseEngineerOptions so that you can set it to true in ConfigureDesignTimeServices when calling services.AddHandlebarsScaffolding.

public void ConfigureDesignTimeServices(IServiceCollection services)
{
    services.AddHandlebarsScaffolding(options =>
    {
        options.EnableNullableReferenceTypes = true;
    });
}

Then in HbsCSharpEntityTypeGenerator.GenerateProperties check property.IsNullable to add a '?' to properties that are nullable in the database.

Metadata will need to be added, so that the Properties.hbs template can be modified to set defaults for non-nullable properties and generate output that uses the null forgiving operator.

public partial class Customer
{
    public string CompanyName { get; set; } = default!;
}

Would you be able to create a new PR that takes this approach?

@tonysneed
Copy link
Contributor

For schema foldering support, would you create another issue and a separate PR? Thanks!

@tonysneed
Copy link
Contributor

@JohnGoldInc Do you plan to open another PR to implement the approach I suggested?

@johngold-onshift
Copy link

johngold-onshift commented Apr 28, 2020 via email

@tonysneed
Copy link
Contributor

@JohnGoldInc Be sure to create a new branch from the latest commit on my master branch (5b2d3d2). Use this branch for your new PR.

For some guidance on creating the PR, please refer to the Contributing Guidelines.

@JohnGoldInc
Copy link
Contributor Author

@tonysneed For EnableNullableReferenceTypes ; do you want me to check in changes to sample project ? (where I am testing it)

@tonysneed
Copy link
Contributor

Yes I think that is a good idea to check in changes to the sample project. That way, I can also run it on my side to see if I get the same behavior.

@JohnGoldInc
Copy link
Contributor Author

@tonysneed I deleted CodeTemplates folder to let it regenerate; I see it would want to remove things like:
// Comment
// My Handlebars Block Helper
{{my-helper}}

I assume you would want me to put that back?

@tonysneed
Copy link
Contributor

tonysneed commented Apr 30, 2020

Oh yes, don't delete the templates. Better if you could just update them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants