当我运行命令Scaffold-DbContext "Server=localhost;Database=MyDatabase;Integrated Security=true" Microsoft.EntityFrameworkCore.SqlServer
我收到错误:
System.ArgumentNullException: Value cannot be null.
Parameter name: proposedIdentifier
at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.Uniquifier(String proposedIdentifier, ICollection`1 existingIdentifiers)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.GenerateCSharpIdentifier(String identifier, ICollection`1 existingIdentifiers, Func`2 singularizePluralizer, Func`3 uniquifier)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.GenerateCSharpIdentifier(String identifier, ICollection`1 existingIdentifiers, Func`2 singularizePluralizer)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpNamer`1.GetName(T item)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUniqueNamer`1.GetName(T item)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.GetEntityTypeName(DatabaseTable table)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTable(ModelBuilder modelBuilder, DatabaseTable table)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTables(ModelBuilder modelBuilder, ICollection`1 tables)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitDatabaseModel(ModelBuilder modelBuilder, DatabaseModel databaseModel)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.CreateFromDatabaseModel(DatabaseModel databaseModel, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ModelScaffolder.Generate(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String projectPath, String outputPath, String rootNamespace, String contextName, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Value cannot be null.
Parameter name: proposedIdentifier.
在我的启动项目中,我有:
public class CustomPluralizerDesignTimeServices : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection services)
{
services.AddSingleton<IPluralizer, HumanizerToIPluralizerAdapter>();
}
}
public class HumanizerToIPluralizerAdapter : IPluralizer
{
public string Pluralize(string name) => name.Pluralize();
public string Singularize(string name) => name.Singularize();
}
当我删除此代码时,脚手架工作。
依赖关系:
DataAccess项目(.NET标准2.0)
启动项目(.NET CORE 2.0)
答案 0 :(得分:2)
看起来像IPluralizer
实施中的错误。确保它没有为某些值返回null或空字符串。