EF 6与dnx项目 [英] EF 6 with a dnx project

查看:248
本文介绍了EF 6与dnx项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个新的ASP.net 5 dnx类库,我用于实体框架。我需要瞄准EF 6,因为我需要的一些功能不在EF 7中。



首先,EF工具(如启用迁移)不在那里。我添加了一个旧样式类库并安装了EF 6,现在命令就在那里。



当我运行启用迁移时,我收到这个错误:


PM>启用迁移



异常使用2参数调用SetData参数:键入
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'
在程序集'Microsoft.VisualStudio.ProjectSystem.VS.Implementation,
版本= 14.1.0.0,文化= neutral,PublicKeyToken = b03f5f7f11d50a3a'是
未标记为可序列化。在
D:\Projects\Rebus\FMS\Code\Current\FMSSupport\FMSSupport\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:720
char:5
+ $ domain.SetData('startUpProject',$ startUpProject)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SerializationException System.NullReferenceException:对象引用未设置为对象的实例
。 at
System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project
project,Int32 shellVersion)at
System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project
项目)
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
命令)对象引用未设置为对象的实例。


我尝试过不同启用迁移的选项,如指定启动项目或contextTypeName。



任何想法?

解决方案

F根据建议,EF6数据项目应该使用现有的.NET Framework类库csproj类型。



即使在遵循建议之后,我仍然收到相同的错误。卸载您的ASP.NET Core项目,然后在适当的csproj上调用 Enable-Migrations 命令应该允许该命令执行。您可以通过右键单击.NET Core项目并选择卸载项目选项来卸载项目。还应该注意的是,软件包管理器控制台窗口具有默认项目:下拉列表选项。您应该使用DbContext选择项目。


I have a new ASP.net 5 dnx class library I am using for entity framework. I need to target EF 6 because some features I need are not in EF 7.

First the EF tools (like enable-migration) were not there. I added an old style class library and installed EF 6 and now the commands are there.

When I run enable migrations I get this error:

PM> Enable-Migrations

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 D:\Projects\Rebus\FMS\Code\Current\FMSSupport\FMSSupport\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.

I have tried different options for enable-migration such as specifying a startup project or the contextTypeName.

Any ideas?

解决方案

Following this recommendation, EF6 data projects should use the existing .NET Framework class library csproj type.

Even after following the recommendations, I was still getting the same error. Unloading your ASP.NET Core project(s) and then invoking the Enable-Migrations command on the appropriate csproj should allow the command to execute. You can unload a project by right-clicking on the .NET Core project and choosing the 'Unload Project' option. It should also be noted that the Package Manager Console window has a 'Default project:' drop-down selection. You should choose the project with your DbContext.

这篇关于EF 6与dnx项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆