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.
Implementing EF 6 and EF Core together is necessary for the following reasons:
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=22.214.171.124, 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?
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
EF6 project to get around the problem.