Pomelo.EntityFrameworkCore.MySql
is the most popular Entity Framework Core provider for MySQL compatible databases. It supports EF Core up to its latest version and uses MySqlConnector for high-performance database server communication.
The following versions of MySqlConnector, EF Core, .NET (Core), .NET Standard and .NET Framework are compatible with published releases of Pomelo.EntityFrameworkCore.MySql
:
Release | Branch | MySqlConnector | EF Core | .NET Standard | .NET (Core) | .NET Framework |
---|---|---|---|---|---|---|
6.0.0- preview.7 |
master | >= 1.4.0-beta.4 | 6.0.0- preview.7 |
N/A | 6.0+ | N/A |
5.0.2 | 5.0-maint | >= 1.3.13 | 5.0.x | 2.1 | 3.0+ | N/A |
3.2.7 | 3.2-maint | >= 0.69.10 < 1.0.0 | 3.1.x | 2.0 | 2.0+ | 4.6.1+ |
2.2.6 | 2.2-maint | >= 0.59.2 < 1.0.0 | 2.2.6 | 2.0 | 2.0+ | 4.6.1+ |
Pomelo.EntityFrameworkCore.MySql
is tested at least against the latest 2 minor versions of MySQL
and MariaDB
. Older versions (e.g. MySQL 5.6) and other server implementations (e.g. Amazon Aurora) are usually compatible to a high degree as well, but are not officially supported or tested.
Currently supported versions are:
Milestone | Status | Release Date |
---|---|---|
6.0.0 | In Development | TBA (see #1413) |
6.0.0-preview.7 | Released | 2021-10-07 |
6.0.0-preview.6 | Released | 2021-10-04 |
6.0.0-preview.5 | Released | 2021-06-27 |
6.0.0-preview.4 | Released | 2021-05-25 |
5.0.2 | Released | 2021-10-04 |
3.2.7 | Released | 2021-10-04 |
3.0.1 | Released | 2019-12-04 |
2.2.6 | Released | 2019-10-15 |
2.1.4 | Released | 2018-11-29 |
Our latest nightly builds currently target EF Core 6.0.0-rc.1
.
To use nightly builds from our Azure DevOps feed, add a NuGet.config
file to your solution root with the following content and enable prereleases:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Pomelo" value="https://pkgs.dev.azure.com/pomelo-efcore/Pomelo.EntityFrameworkCore.MySql/_packaging/pomelo-efcore-public/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
Ensure that your .csproj
file contains the following reference:
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.2" />
Add Pomelo.EntityFrameworkCore.MySql
to the services configuration in your the Startup.cs
file of your ASP.NET Core project:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Replace with your connection string.
var connectionString = "server=localhost;user=root;password=1234;database=ef";
// Replace with your server version and type.
// Use 'MariaDbServerVersion' for MariaDB.
// Alternatively, use 'ServerVersion.AutoDetect(connectionString)'.
// For common usages, see pull request #1233.
var serverVersion = new MySqlServerVersion(new Version(8, 0, 26));
// Replace 'YourDbContext' with the name of your own DbContext derived class.
services.AddDbContext<YourDbContext>(
dbContextOptions => dbContextOptions
.UseMySql(connectionString, serverVersion)
// The following three options help with debugging, but should
// be changed or removed for production.
.LogTo(Console.WriteLine, LogLevel.Information);
.EnableSensitiveDataLogging()
.EnableDetailedErrors()
);
}
}
View our Configuration Options Wiki Page for a list of common options.
Check out our Integration Tests for an example repository that includes an ASP.NET Core MVC Application.
There are also many complete and concise console application samples posted in the issue section (some of them can be found by searching for Program.cs
).
Refer to Microsoft's EF Core Documentation for detailed instructions and examples on using EF Core.
Use the EF Core tools to execute scaffolding commands:
dotnet ef dbcontext scaffold "Server=localhost;User=root;Password=1234;Database=ef" "Pomelo.EntityFrameworkCore.MySql"
One of the easiest ways to contribute is to report issues, participate in discussions and update the wiki docs. You can also contribute by submitting pull requests with code changes and supporting tests.
We are always looking for additional core contributors. If you got a couple of hours a week and know your way around EF Core and MySQL, give us a nudge.
引入Pomelo.EntityFrameworkCore.MySql程序包 ConfigureServices // other service configurations go here // replace "YourDbContext" with the class name of your DbContext services.AddDbC
Method ‘Create’ in type ‘Pomelo.EntityFrameworkCore.MySql.Query.ExpressionVisitors.Internal.MySqlSqlTranslatingExpressionVisitorFactory’ from assembly ‘Pomelo.EntityFrameworkCore.MySql, Version=3.1.0.