简体   繁体   English

添加迁移 asp.net web API

[英]Add Migration with asp.net web API

 
PM> Add-Migration InitialCreate
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.P
rojectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=17.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\Ctop\.nuget\packages\entityframework\6.0.0\tools\EntityFramework.psm1
:609 char:5
+     $domain.SetData('project', $project)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException
 
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.P
rojectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=17.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\Ctop\.nuget\packages\entityframework\6.0.0\tools\EntityFramework.psm1
:610 char:5
+     $domain.SetData('contextProject', $contextProject)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException
 
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.P
rojectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=17.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\Ctop\.nuget\packages\entityframework\6.0.0\tools\EntityFramework.psm1
:611 char:5
+     $domain.SetData('startUpProject', $startUpProject)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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)
   at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory)
   at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Object reference not set to an instance of an object.
PM> 

I'm trying to add migration to my asp.net Web Api project but I got this error after adding the command Add-Migration InitialCreate and my database connection is working我正在尝试将迁移添加到我的 asp.net Web Api 项目,但是在添加命令 Add-Migration InitialCreate 并且我的数据库连接正常后出现此错误

did you try Serializable attribute to the class which you want to serialize.您是否尝试将 Serializable 属性设置为要序列化的 class。

 [Serializable]
    public class OrgPermission

Other answers suggest this is an issue with your startup project.其他答案表明这是您的启动项目的问题。

As your project is a library, you could try setting your unit test project as your startup project由于您的项目是一个库,您可以尝试将单元测试项目设置为您的启动项目

I just install the package我只是安装 package

Microsoft.EntityFrameworkCore.Tools Microsoft.EntityFrameworkCore.工具

and use the Following Migration Command并使用以下迁移命令

EntityFrameworkCore\Enable-Migrations

Add-Migration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM