从下面的堆栈跟踪中,我无法分辨错误消息的错误。我用--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
关于如何解决问题(项目编译正常)的任何提示将不胜感激
这是搜索Microsoft.EntityFrameworkCore.Utilities.Check.NotNull
的第一个结果之一,所以我将添加我的愚蠢错误:
我为不同的DatabaseContext重构了一个类,然后在来自不同上下文的两个Join
查询之间调用IQueryable
--显然你不能在EntityFramework中做到这一点
我认为你的问题是你的模型,你不装饰[Key]
属性或不使用HasKey
。请分享您的代码。