c# - 实体框架无法创建任何迁移
问题描述
我想开始使用 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 的示例项目,那么迁移似乎可以工作。我也尝试过创建一个类库项目并在那里完成迁移,但结果相同。
解决方案
正如@Ivan Stoev 指出的那样,我使用了错误的 EF 版本。这是一篇简短的文章,解释了EF 和 EF Core之间的区别。
推荐阅读
- terraform - 如何在 terraform 数据资源 aws_iam_policy_document 中传递 s3 arns 列表
- reactjs - 使用状态机时如何在向导中配置动态表单字段
- python - 使用 python 请求从网页中抓取数据
- hardware - 在计算中,UMA 是什么意思?
- jenkins - 从存储库(bitbucket)读取 openshift 模板时出现问题
- r - R中的rbind - 匹配列名
- flutter - 任务 app:mergeDebugNativeLibs 和 app:mergeDebugJavaResource 的 Flutter 失败
- shell - 如何防止 escapeshellarg 函数转义重音字符?
- google-analytics - 使用 Google 跟踪代码管理器时将重复的 URL 分析与规范 URL 合并
- angular - 如何过滤带有嵌套对象的 PrimeNG 表?