相关疑难解决方法(0)

在单独的程序集中启用具有上下文的迁移?

我有一个项目,我想update-database反对我,但我在一个单独的项目中有我的模型和上下文.

如果我运行,enable-migrations我会收到此错误:在程序集"MyProject"中找不到上下文类型.

这可能是因为我的Context在MyProject.MVC中.

如果我enable-migrations针对MyProject.MVC 运行,我必须添加一个app配置文件.我不想这样做,因为我想在许多项目中使用代码.

那么我可以enable-migrations针对MyProject 运行并以某种方式告诉它在MyProject.MVC中查找Context吗?

.net c# entity-framework asp.net-mvc-4 ef-migrations

64
推荐指数
2
解决办法
5万
查看次数

无法在类库中启用Entity Framework的迁移

我刚刚加入了EF 5并使用了他们的代码优先迁移工具,但是当我尝试启用迁移时,我似乎遇到了错误.

我输入Enable-Migrations包管理器控制台,然后说

没有从当前项目中找到的DbContext派生的类.
编辑生成的Configuration类以指定启用迁移的上下文.
为项目MyApp.MvcUI启用了代码优先迁移.

然后它在我的MvcUI项目中创建一个Migrations文件夹和一个Configuration类.事实上,我的DbContext存在于名为MyApp.Domain的类库项目中.它应该在该项目中完成所有这一切,并且应该没有问题找到我的DbContext.

c# entity-framework ef-code-first ef-migrations entity-framework-5

43
推荐指数
2
解决办法
2万
查看次数

VS 2015 ASP.NET Web API(EF6)和Xamarin Enable-Migrations失败

我正在开发一个项目,它将使用ASP.NET Web API作为数据服务,并使用Xamarin便携式应用程序作为客户端.

我正在尝试在Web应用程序中启用迁移,但是我收到以下错误:

Enable-Migrations -enableautomaticmigrations -ContextTypeName MyProject.Models.ApplicationDbContext -ProjectName MyProject -StartupProjectName MyProject.App -Verbose
Using StartUp project 'MyProject.App'.
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.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\weitz\.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:718 char:5
+     $domain.SetData('project', $project)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException

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.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\weitz\.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:719 char:5
+     $domain.SetData('contextProject', $contextProject) …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework ef-migrations asp.net-web-api xamarin.forms

18
推荐指数
1
解决办法
635
查看次数

启用 - 迁移安装错误

我在其中一个项目上启用迁移时遇到了问题.我Enable-Migrations从Nuget控制台执行命令并收到错误说:

Exception calling "SetData" with "2" argument(s): "Type 
'Microsoft.VisualStudio.TeamArchitect.ModelingProject.ModelProjectAutomationObject' in assembly 
'Microsoft.VisualStudio.TeamArchitect.ModelingProject, Version=11.0.0.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At D:\Solution\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:391 char:5
+     $domain.SetData('startUpProject', $startUpProject)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException
Run Code Online (Sandbox Code Playgroud)

有没有人在此之前遇到这个问题可以指出我正确的方向.

环境:
.NET 4.5
实体框架5
Visual Studio 2012 Update 2

entity-framework ef-migrations entity-framework-5 visual-studio-2012

17
推荐指数
1
解决办法
1万
查看次数

EF 6 - 使用2个参数调用SetData的错误异常

我有一个包含多个项目的解决方案.DBContext文件和Models位于ClassLibrary项目中.这个项目有EF 6.1.3,它运行在.NET 4.5.2上.模型和DBContext文件采用不同的文件结构,我的意思是模型在Project/Data/Model中,而DBContext在Data文件夹中.此项目似乎已启用到现有数据库的迁移.开发团队过去只是通过构建项目来重新创建数据库.它也有:

AutomaticMigrationsEnabled = true;
Run Code Online (Sandbox Code Playgroud)

我正在尝试正确使用迁移,并尝试按照以下方式查看PackageManagerConsole正确反应.

Enable-Migrations
Add-Migration InitialCreate –IgnoreChanges
Run Code Online (Sandbox Code Playgroud)

两者都导致以下错误:

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.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\Temp\.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:718 char:5
+     $domain.SetData('project', $project)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException   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.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\Temp\.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:719 char:5
+     $domain.SetData('contextProject', $contextProject)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : …
Run Code Online (Sandbox Code Playgroud)

c# database ef-migrations entity-framework-6

10
推荐指数
1
解决办法
2166
查看次数

启用 - 迁移"对象引用未设置为对象的实例"

我刚刚创建了一个新的服务结构服务,它将使用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 …
Run Code Online (Sandbox Code Playgroud)

entity-framework azure-elastic-scale azure-sql-database

7
推荐指数
1
解决办法
9686
查看次数