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

Exception thrown when table naming is set to plural, but the table name in the database is singular. #38

Closed
tjackadams opened this issue Nov 5, 2019 · 3 comments

Comments

@tjackadams
Copy link
Contributor

Just want to say a great project to start off with! I'm currently just testing it and i came across this issue.

so my generation.yml configuration contains this snippet

database:
  connectionString: <omitted>
  provider: SqlServer
  tables:
    - ReportOutputType
  tableNaming: Plural

The table naming option is set to plural, but the table name is singular. I know this is only one table, but the database we are looking to scaffold has a lot more tables and unfortunately a mix of single and plural table names (the naming convention wasn't strict....).

The exception is as follows

System.ArgumentNullException: Value cannot be null. (Parameter 'input')
at System.Text.RegularExpressions.Regex.IsMatch(String input)
at System.Text.RegularExpressions.Regex.IsMatch(String input, String pattern)
at EntityFrameworkCore.Generator.ModelGenerator.ToLegalName(String name) in C:\projects\entityframeworkcore-generator \src\EntityFrameworkCore.Generator.Core\ModelGenerator.cs:line 581
at EntityFrameworkCore.Generator.ModelGenerator.ToClassName(String tableName, String tableSchema) in C:\projects\enti tyframeworkcore-generator\src\EntityFrameworkCore.Generator.Core\ModelGenerator.cs:line 562
at EntityFrameworkCore.Generator.ModelGenerator.CreateEntity(EntityContext entityContext, DatabaseTable tableSchema) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator.Core\ModelGenerator.cs:line 104
at EntityFrameworkCore.Generator.ModelGenerator.GetEntity(EntityContext entityContext, DatabaseTable tableSchema, Boolean processRelationships, Boolean processMethods) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator.Core\ModelGenerator.cs:line 79
at EntityFrameworkCore.Generator.ModelGenerator.Generate(GeneratorOptions options, DatabaseModel databaseModel, IRelationalTypeMappingSource typeMappingSource) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator.Core\ModelGenerator.cs:line 69
at EntityFrameworkCore.Generator.CodeGenerator.Generate(GeneratorOptions options) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator.Core\CodeGenerator.cs:line 47
at EntityFrameworkCore.Generator.GenerateCommand.OnExecute(CommandLineApplication application) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator\GenerateCommand.cs:line 76
--- End of stack trace from previous location where exception was thrown ---
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at EntityFrameworkCore.Generator.Program.Main(String[] args) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator\Program.cs:line 50

I narrowed it down to this section of code, looks like its actually caused by Humanizer.

private string EntityName(string name)
{
var tableNaming = _options.Database.TableNaming;
var entityNaming = _options.Data.Entity.EntityNaming;
if (tableNaming != TableNaming.Plural && entityNaming == EntityNaming.Plural)
name = name.Pluralize();
else if (tableNaming != TableNaming.Singular && entityNaming == EntityNaming.Singular)
name = name.Singularize();
return name;
}

because the table name is already singular, humanizer returns null from the Singularize method which then carriers on and throws the exception.

Looks like the override Singularize should fix this, but i noticed there are quite a few usages of this throughout the project.

I can open a PR to update them all. Whats your thoughts?

@tjackadams
Copy link
Contributor Author

apologies, i missed this one #17

Although it has been open a while, shall i still open a PR?

@pwelter34
Copy link
Member

yes please. thank you!

@pwelter34
Copy link
Member

fixed by PR

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

No branches or pull requests

2 participants