如何解决entity framework核心System.ArgumentNullException

How to solve entity framework core System.ArgumentNullException

从下面的堆栈跟踪中,我无法通过错误消息判断出什么问题。我 运行 带有 --verbose 标志的迁移命令希望它能帮助查明问题,但 zilch。

  dotnet ef migrations add migwl3 --verbose

我找不到名为 key

的参数
  System.ArgumentNullException: Value cannot be null.
  Parameter name: key
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T   value, String parameterName)
   at     Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions.SqlServer(IKey key)
   at    Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.    <Add>d__41.MoveNext()
   at System.Linq.Enumerable.<CastIterator>d__35`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at     Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.   <Add>d__29.MoveNext()
   at     Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.   <DiffCollection>d__56`1.MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at      Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.S      ort(IEnumerable`1 operations, DiffContext diffContext)
  at      Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.Scaf      foldMigration(String migrationName, String rootNamespace, String      subNamespace)
   at     Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMig      ration(String name, String outputDir, String contextType)
  at      Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(S    tring name, String outputDir, String contextType)
  at     Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
  at     Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Exec     ute(Action action)
 Value cannot be null.
 Parameter name: key

任何关于如何归零问题的提示(项目编译良好)将不胜感激

我认为你的问题是你的模型没有装饰 [Key] 属性或者 不使用 HasKey。 请分享您的代码。

这是搜索 Microsoft.EntityFrameworkCore.Utilities.Check.NotNull 的第一批结果之一,所以我将添加我的愚蠢错误:

我将 class 重构为不同的 DatabaseContext,然后在来自这些不同上下文的两个 IQueryable 查询之间调用 Join——显然你不能在 EntityFramework