Exception thrown when table naming is set to plural, but the table name in the database is singular.
tjackadams opened this issue · comments
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.
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?
apologies, i missed this one #17
Although it has been open a while, shall i still open a PR?
yes please. thank you!
fixed by PR