数据库提供程序Database Providers

Entity Framework Core 可通过名为数据库提供程序的插件库访问许多不同的数据库。Entity Framework Core can access many different databases through plug-in libraries called database providers.

当前提供程序Current providers

重要

EF Core 提供程序由多种源生成。EF Core providers are built by a variety of sources. 并非所有提供程序均作为 Entity Framework Core 项目的组成部分进行维护。Not all providers are maintained as part of the Entity Framework Core Project. 考虑使用提供程序时,请务必评估质量、授权、支持等因素,确保其满足要求。When considering a provider, be sure to evaluate quality, licensing, support, etc. to ensure they meet your requirements. 同时也请务必查看每个提供程序的文档,详细了解版本兼容性信息。Also make sure you review each provider's documentation for detailed version compatibility information.

NuGet 程序包NuGet Package 支持的数据库引擎Supported database engines 维护商/供应商Maintainer / Vendor 备注/要求Notes / Requirements 有用的链接Useful links
Microsoft.EntityFrameworkCore.SqlServerMicrosoft.EntityFrameworkCore.SqlServer SQL Server 2008 及以上版本SQL Server 2008 onwards EF Core 项目 (Microsoft)EF Core Project (Microsoft) docsdocs
Microsoft.EntityFrameworkCore.SqliteMicrosoft.EntityFrameworkCore.Sqlite SQLite 3.7 及以上版本SQLite 3.7 onwards EF Core 项目 (Microsoft)EF Core Project (Microsoft) docsdocs
Microsoft.EntityFrameworkCore.InMemoryMicrosoft.EntityFrameworkCore.InMemory EF Core 内存中数据库EF Core in-memory database EF Core 项目 (Microsoft)EF Core Project (Microsoft) 仅用于测试For testing only docsdocs
Microsoft.EntityFrameworkCore.CosmosMicrosoft.EntityFrameworkCore.Cosmos Azure Cosmos DB SQL APIAzure Cosmos DB SQL API EF Core 项目 (Microsoft)EF Core Project (Microsoft) 仅预览版Preview only 博客blog
Npgsql.EntityFrameworkCore.PostgreSQLNpgsql.EntityFrameworkCore.PostgreSQL postgresqlPostgreSQL Npgsql 开发团队Npgsql Development Team docsdocs
Pomelo.EntityFrameworkCore.MySqlPomelo.EntityFrameworkCore.MySql MySQL、MariaDBMySQL, MariaDB Pomelo Foundation 项目Pomelo Foundation Project 自述文件readme
Pomelo.EntityFrameworkCore.MyCatPomelo.EntityFrameworkCore.MyCat MyCAT 服务器MyCAT Server Pomelo Foundation 项目Pomelo Foundation Project 仅预发行版Prerelease only 自述文件readme
EntityFrameworkCore.SqlServerCompact40EntityFrameworkCore.SqlServerCompact40 SQL Server Compact 4.0SQL Server Compact 4.0 Erik Ejlskov JensenErik Ejlskov Jensen .NET Framework.NET Framework wikiwiki
EntityFrameworkCore.SqlServerCompact35EntityFrameworkCore.SqlServerCompact35 SQL Server Compact 3.5SQL Server Compact 3.5 Erik Ejlskov JensenErik Ejlskov Jensen .NET Framework.NET Framework wikiwiki
EntityFrameworkCore.JetEntityFrameworkCore.Jet Microsoft Access 文件Microsoft Access files BubiBubi .NET Framework.NET Framework 自述文件readme
MySql.Data.EntityFrameworkCoreMySql.Data.EntityFrameworkCore MySQLMySQL MySQL 项目 (Oracle)MySQL project (Oracle) docsdocs
FirebirdSql.EntityFrameworkCore.FirebirdFirebirdSql.EntityFrameworkCore.Firebird Firebird 2.5 和 3.xFirebird 2.5 and 3.x Jiří ČinčuraJiří Činčura docsdocs
EntityFrameworkCore.FirebirdSqlEntityFrameworkCore.FirebirdSql Firebird 2.5 和 3.xFirebird 2.5 and 3.x Rafael AlmeidaRafael Almeida wikiwiki
IBM.EntityFrameworkCoreIBM.EntityFrameworkCore Db2、InformixDb2, Informix IBMIBM Windows 版本Windows version 博客blog
IBM.EntityFrameworkCore-lnxIBM.EntityFrameworkCore-lnx Db2、InformixDb2, Informix IBMIBM Linux 版本Linux version 博客blog
IBM.EntityFrameworkCore-osxIBM.EntityFrameworkCore-osx Db2、InformixDb2, Informix IBMIBM macOS 版本macOS version 博客blog
EntityFrameworkCore.OpenEdgeEntityFrameworkCore.OpenEdge Progress OpenEdgeProgress OpenEdge Alex WieseAlex Wiese 自述文件readme
Devart.Data.Oracle.EFCoreDevart.Data.Oracle.EFCore Oracle 9.2.0.4 及以上版本Oracle 9.2.0.4 onwards DevArtDevArt 已付Paid docsdocs
Devart.Data.PostgreSql.EFCoreDevart.Data.PostgreSql.EFCore PostgreSQL 8.0 及以上版本PostgreSQL 8.0 onwards DevArtDevArt 已付Paid docsdocs
Devart.Data.SQLite.EFCoreDevart.Data.SQLite.EFCore SQLite 3 及以上版本SQLite 3 onwards DevArtDevArt 已付Paid docsdocs
Devart.Data.MySql.EFCoreDevart.Data.MySql.EFCore MySQL 5 及以上版本MySQL 5 onwards DevArtDevArt 已付Paid docsdocs

未来的提供程序Future Providers

Cosmos DBCosmos DB

我们一直在为 Cosmos DB 中的 SQL API 开发 EF Core 提供程序。We have been developing an EF Core provider for the SQL API in Cosmos DB. 这将是我们首次推出完整的面向文档的数据库提供程序,通过此次尝试积累的经验将用于改进今后发布的 EF Core 以及其他非关系提供程序的设计。This will be the first complete document-oriented database provider we have produced, and the learnings from this exercise are going to inform improvements in the design of future releases of EF Core and possibly other non-relational providers. 可以从 NuGet 库获取预览版。A preview is available on the NuGet Gallery.

OracleOracle

Oracle .NET 团队已宣布,他们计划在 2018 年第三季度左右针对 EF Core 发布第一方提供程序。The Oracle .NET team has announced they are planning to release a first-party provider for EF Core approximately in the third quarter of 2018. 有关详细信息,请参阅其关于 .NET Core 和 Entity Framework Core 方向的声明See their statement of direction for .NET Core and Entity Framework Core for more information. 请在 Oracle 社区网站上提出有关此提供程序的任何问题(包括发布时间线)。Please direct any questions about this provider, including the release timeline, to the Oracle Community Site.

与此同时,EF 团队还为 Oracle 数据库提供了示例 EF Core 提供程序In the meanwhile, the EF team has produced a sample EF Core provider for Oracle databases. 此项目并不旨在生成 Microsoft 拥有的 EF Core 提供程序。The purpose of the project is not to produce an EF Core provider owned by Microsoft. 我们之所以启动此项目是为了确定 EF Core 的关系功能与基础功能之间的差距,我们必须弥补这些差距,才能更好地支持 Oracle。We started the project to identify gaps in EF Core's relational and base functionality which we needed to address in order to better support Oracle. 它还应有助于 Oracle 或第三方快速开始开发用于 EF Core 的 Oracle 提供程序。It should also help Oracle or third parties jumpstart the development of Oracle providers for EF Core.

对实现该示例有益的建议我们都会考虑。We will consider contributions that improve the sample implementation. 我们也欢迎并鼓励社区以该示例为基础为 EF Core 创建开源 Oracle 提供程序。We would also welcome and encourage a community effort to create an open-source Oracle provider for EF Core, using the sample as a starting point.

向应用程序添加数据库提供程序Adding a database provider to your application

EF Core 的大多数数据库提供程序都是作为 NuGet 包分发的。Most database providers for EF Core are distributed as NuGet packages. 这意味着可使用命令行中的 dotnet 工具来安装它们:This means they can be installed using the dotnet tool in the command line:

dotnet add package provider_package_name

或者在 Visual Studio 中,使用 NuGet 包管理器控制台:Or in Visual Studio, using NuGet's Package Manager Console:

install-package provider_package_name

安装后,需采用 OnConfiguring 方法或 AddDbContext 方法(如果使用的是依赖关系注入容器)在 DbContext 中配置提供程序。Once installed, you will configure the provider in your DbContext, either in the OnConfiguring method or in the AddDbContext method if you are using a dependency injection container. 例如,以下行使用传递的连接字符串配置 SQL Server 提供程序:For example, the following line configures the SQL Server provider with the passed connection string:

optionsBuilder.UseSqlServer(
    "Server=(localdb)\mssqllocaldb;Database=MyDatabase;Trusted_Connection=True;");

数据库提供程序可扩展 EF Core,启用特定数据库特有的功能。Database providers can extend EF Core to enable functionality unique to specific databases. 一些概念为大多数据库共有,它们包含于 EF Core 主要组件中。Some concepts are common to most databases, and are included in the primary EF Core components. 此类概念包括 LINQ 中的表达查询、事务以及对象从数据库加载后的跟踪更改。Such concepts include expressing queries in LINQ, transactions, and tracking changes to objects once they are loaded from the database. 另一些概念特定于具体的提供程序。Some concepts are specific to a particular provider. 例如,通过 SQL Server 提供程序可配置内存优化表(SQL Server 的一种特定功能)。For example, the SQL Server provider allows you to configure memory-optimized tables (a feature specific to SQL Server). 其他一些概念特定于某一类提供程序。Other concepts are specific to a class of providers. 例如,用于关系数据库的 EF Core 提供程序构建于公共 Microsoft.EntityFrameworkCore.Relational 库上,该库提供的 API 可用于配置表和列映射、外键约束等。提供程序通常作为 NuGet 包分发。For example, EF Core providers for relational databases build on the common Microsoft.EntityFrameworkCore.Relational library, which provides APIs for configuring table and column mappings, foreign key constraints, etc. Providers are usually distributed as NuGet packages.

重要

发布 EF Core 的新补丁版本时,其中通常包含 Microsoft.EntityFrameworkCore.Relational 包的更新。When a new patch version of EF Core is released, it often includes updates to the Microsoft.EntityFrameworkCore.Relational package. 添加关系数据库提供程序时,该包将成为应用程序的传递依赖项。When you add a relational database provider, this package becomes a transitive dependency of your application. 但许多提供程序是独立于 EF Core 发布的,因此可能不会更新为依赖该包的较新补丁版本。But many providers are released independently from EF Core and may not be updated to depend on the newer patch version of that package. 为确保能修复所有 bug,建议将 Microsoft.EntityFrameworkCore.Relational 补丁版本添加为应用程序的直接依赖项。In order to make sure you will get all bug fixes, it is recommended that you add the patch version of Microsoft.EntityFrameworkCore.Relational as a direct dependency of your application.