EF 6 with dnx project

I have a new ASP.net 5 dnx class library that I use for entity structure. I need to configure EF 6 because some of the features I need are not included in EF 7.

At first, there were no EF tools (e.g. enable-migration). I added the old style class library and installed EF 6, and now there are commands.

When I run allowed migrations, I get this error:

PM> Enable-Migrations

Throw an exception "SetData" with argument "2": "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in the assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version = 14.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a 'are not marked as serializable. 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: the reference to the object is not installed in the object instance. in System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes (project project, Int32 shellVersion) under System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject (project project) in System.Data.Entity.Migrations.MigrationsDomainCommand. GetFacade (String configurationTypeName, Boolean useContextWorkingDirectory) with System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable (String contextTypeName) in System.Data.Entity.Migrations.EnableMigrationsCommand <. > C__DisplayClass2 <.. ctor> b__0 () in System.Data.Entity.Migrations.MigrationsDomainCommand.Execute (Action command) The object reference is not installed in the object instance.

I tried various options for enable-migration, such as indicating the start of the project or the name contextTypeName.

Any ideas?

+8
c # asp.net-core entity-framework-6 dnx
source share
3 answers

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

Even after following the recommendations, I was still getting the same error. Unloading the ASP.NET Core project and then calling the Enable-Migrations command on the appropriate csproj should allow the command to execute. You can unload the project by right-clicking on the .NET Core project and selecting the "Unload Project" option. It should also be noted that in the package manager console window there is a drop-down list called “Project by default”. You must select a project using DbContext.

+3
source share

This is because ASP.NET Core introduced the new system / type of the project system (see package.config vs project.json ) and the old EF tools do not know how to work with the new system (project.json). Perhaps it would be easiest to create a new project and transfer its code if you want to return to EF6.

Interesting (well, unfortunately, actually) they backtrack from project.json: http://xoofx.com/blog/2016/05/11/goodbye-project-json/

0
source share

I had the same problem. Just setting up an initial project from ASP.NET Core for my .NET Framework Lib does the trick for me =) Now I can perform EF6 migrations, as usual, with the Add-Migration command ...

PS Sorry for my eng.

0
source share

All Articles