entity-framework – 启用 – 迁移“对象引用未设置为对象的实例”

前端之家收集整理的这篇文章主要介绍了entity-framework – 启用 – 迁移“对象引用未设置为对象的实例”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚创建了一个新的服务结构服务,它将定期尝试使用Entity Framework和Elastic Client Database库将一些模型保存到sql Azure.我正在尝试尽可能地对sql Azure Elastic Sc​​ale Client Library EF示例( Elastic DB Tools EF Sample)进行建模.我正处于需要启用迁移的位置,但是当我运行Enable-Migrations时,我收到以下错误消息.我正在使用ContextTypeName参数,因为如果我最终将针对具有不同模型的相同数据库使用不同的服务结构服务,那么它听起来就像是必需的.有什么建议?
PM> Enable-Migrations -ContextTypeName "ServiceHealth.DbService"
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation,Version=14.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a' is 
not marked as serializable."
At C:\eNowCloud\eNow.MicroServices\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:720 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.GetProjectTypes(Project project,Int32 shellVersion)
   at System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project project)
   at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName,Boolean useContextWorkingDirectory)
   at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName)
   at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Object reference not set to an instance of an object.

解决方法

我通过使用db上下文为我的.NET框架dll指定Enable-Migrations命令的-StartUpProjectName参数来解决相同的异常问题.问题可能在于奇怪的启动项目–.IsWebProject()(在我的例子中是asp.core)中的问题.查看 Enable-Migrations Exception calling “SetData” with “2” argument(s)的更多细节答案.

猜你在找的MsSQL相关文章