首页 > 解决方案 > 实体框架无法创建任何迁移

问题描述

我想开始使用 EF 并遵循Microsoft 的文档。一切都很好,但是当我尝试创建初始迁移时,PM 会引发异常。

Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\Anton\.nuget\packages\entityframework\6.2.0\tools\EntityFramework.psm1:720 char:5
+     $domain.SetData('project', $project)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetPropertyValue[T](Project project, String propertyName)

我用谷歌搜索了很多,发现其他人也有同样的问题。我已经尝试了那里的所有解决方案,尤其是包括设置启动项目的解决方案,但这似乎不起作用。例如,运行-StartupProjectName WebApplication1只会抛出一个错误,说-StartupProjectName does not exist.如果我下载了一个使用 EF 的示例项目,那么迁移似乎可以工作。我也尝试过创建一个类库项目并在那里完成迁移,但结果相同。

标签: c#entity-framework

解决方案


正如@Ivan Stoev 指出的那样,我使用了错误的 EF 版本。这是一篇简短的文章,解释了EF 和 EF Core之间的区别。


推荐阅读