下面是从Getting Started with ASP.NET Core and Entity Framework 6的摘录:工具两者的EntityFramework 6和的EntityFramework核心并排的部分,在n层溶液
"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 6和的EntityFramework核心侧在n层解决方案中并排。
解决方案:
- 核心ASP.NET Web应用程序(.NET框架)与个人用户帐户验证
- 的Windows类库文件(.dll)包含BLL & DAL
实施EF 6和EF Core并排的原因是:
-
个
- EF核心1.x的执行问题(迁移,许多到零关系)
- 个人用户帐户的身份验证ASP.NET中的核心有Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext
- 此使用的依赖 - 案例将实现目前依赖于实体框架BreezeJS 6
我可以成功添加迁移到ASP.NET核心Web应用程序如下:
PM> EntityFrameworkCore\Add-Migration InitialCreate
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) ...
如果我卸载ASP.NET核心Web应用程序,那么我就可以成功添加EF6迁移到Windows类:但是,试图迁移添加到Windows类库时,我得到一个异常库的步骤如下:
PM> EntityFramework\enable-migrations
PM> EntityFramework\add-migration InitialCreate
现在我已经在两个项目中进行了初始迁移。
然而,当我运行ASP.NET核心Web应用程序,我得到了几个运行时异常:
如果我有我的System.Data.Entity.DbContext的自定义实现参数的构造函数,然后我得到以下运行时异常:
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) …
这是通过删除默认构造函数来解决的。
当我尝试注册一个用户,下面的异常被抛出:
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
Q - 我在正确的轨道上?现在这只是一个SQL Server身份验证问题?或者,还有其他问题涉及?
关于如何在EF 6和EF内核上运行.Net 4.6 MVC项目的任何想法?我不想一次性将所有内容迁移到EF内核,但确实需要一些功能来加速导入和批量更新。 – TWilly
[EF核心文档](https://docs.microsoft.com/en-us/ef/core/)指出EF Core是跨平台的。我的理解是,为了实现跨平台,EF Core必须运行在.NET核心应用程序中。但是,[NuGet](https://www.nuget。org/packages/Microsoft.EntityFrameworkCore /)在依赖项部分列出了.NET Framework 4.5.1。也许有人会说如果可以在.NET 4x应用程序中运行EF Core。 FWIW,您可以找到[功能比较](https://docs.microsoft.com/en-us/ef/efcore-and-ef6/features)以提供信息。 – RandyDaddis