支架-DbContext抛出ArgumentNullException

时间:2018-11-14 20:25:21

标签: sql-server entity-framework-core ef-database-first ef-core-2.1

当我尝试搭建我们的一个数据库时,出现以下异常。

For foreign key FK_ActivityEvent_ActivityCode on table dbo.ActivityEvent, unable to find the column called UniqActivityCode on the foreign key's principal table, dbo.ActivityCode. Skipping foreign key.
For foreign key FK_Line_Line on table dbo.Line, unable to find the column called UniqLine on the foreign key's principal table, dbo.Line. Skipping foreign key.
For foreign key FK_MarketingLine_MarketingLine on table dbo.MarketingLine, unable to find the column called UniqMarketingLine on the foreign key's principal table, dbo.MarketingLine. Skipping foreign key.
System.ArgumentNullException: Value cannot be null.
Parameter name: column
  at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
  at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.GetPropertyName(DatabaseColumn column)
  at System.Linq.Enumerable.SelectListIterator`2.ToArray()
  at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
  at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitPrimaryKey(EntityTypeBuilder builder, 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.Create(DatabaseModel databaseModel, Boolean useDatabaseNames)
  at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String namespace, String language, String contextDir, String contextName, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
  at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, 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 outputDbContextDir, 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: column

我成功地搭建了一个数据库,因此我确定我正确地使用了scaffold命令。另外,我可以使用在Scaffold-DbContext命令中输入的连接字符串访问数据库。

我安装了以下软件包:

install-package microsoft.entityframeworkcore.sqlserver
install-package microsoft.entityframeworkcore.tools

在Windows 10上使用.NET Core Console App 2.1。

不确定是否与此相关,但是当我尝试在ssms中扩展Database Diagrams时收到以下消息。 (我没有在成功搭建好的其他数据库上收到此消息)

enter image description here

0 个答案:

没有答案