implement both EntityFramework 6 and EntityFramework Core side-by-side in a n-tier solution

asp.net-core entity-framework-6 entity-framework-core

Question

An extract from Getting Started with Entity Framework 6 with ASP.NET Core is shown below:

"The recommended way to use Entity Framework 6 in an ASP.NET Core 1.0 application is to put the EF6 context and model classes in a class library project (.csproj project file) that targets the full framework. Add a reference to the class library from the ASP.NET Core project. "

EntityFramework Core and EntityFramework 6 will be implemented simultaneously by I want to: in an n-tier system.

Solution:

  • Individual User Accounts Authentication in an ASP.NET Core Web Application
  • BLL and DAL are included in the Windows Class Libraries (.dll)

Implementing EF 6 and EF Core together is necessary for the following reasons:

  • Problems implementing EF Core 1.x (migrations, many-to-zero relationships)
  • Microsoft is a need for the individual user account authentication in ASP.NET Core. AspNetCore. Identity. EntityFrameworkCore. IdentityDbContext
  • BreezeJS, which presently relies on Entity Framework 6, will be implemented in this use case.

I'm able to successfully add the following migrations to the ASP.NET Core Web Application:

PM> EntityFrameworkCore\Add-Migration InitialCreate

When trying to add migrations to the Windows class library, I see the following exception:

PM> EntityFramework\Add-Migration InitialCreate

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:\Src\Hcs.NetCore\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:720 char:5 + $domain.SetData('startUpProject', $startUpProject) ...

I can successfully add EF6 migrations to the Windows class library by doing the following steps after unloading the ASP.NET Core Web Application:

PM> EntityFramework\enable-migrations
PM> EntityFramework\add-migration InitialCreate

I currently have both projects' first migrations.

However, I see the following runtime errors when I attempt to execute the ASP.NET Core Web Application:

I receive the following runtime error if my custom implementation of System.Data.Entity.DbContext has a constructor without parameters:

System.Data.SqlClient.SqlException was unhandled by user code …
Message=A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) …

By getting rid of the default constructor, it was fixed.

This error was raised when I tried to register a user:

System.Data.SqlClient.SqlException (0x80131904): Cannot open database "xxx" requested by the login. The login failed. Login failed for user yyy\zzz'. at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) at

Is this the appropriate path for me? Is the problem now restricted to SQL Server authentication? Or are there other problems at play?

1
1
11/12/2016 5:19:56 PM

Accepted Answer

ZZZ_tmp
1
11/12/2016 6:08:20 PM

Popular Answer

Since ASP.NET Core projects weren't there when EF6 commands were developed, they don't know how to operate with them. These projects will probably need to be unloaded before using EF6 commands.

Additionally, you may be able to clearly state-StartupProject EF6 project to get around the problem.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow