Pomelo.EntityFrameworkCore.MySql
is the most popular Entity Framework Core provider for MySQL compatible databases. It supports EF Core 3.1 (and lower) and uses MySqlConnector for high-performance database server communication.
The following versions of MySqlConnector, EF Core and .NET Standard are compatible with Pomelo.EntityFrameworkCore.MySql
:
Release | Branch | MySqlConnector | EF Core | .NET Standard | .NET (Core) | .NET Framework |
---|---|---|---|---|---|---|
5.0.0-alpha.2 | master | >= 1.1.0 | 5.0.x | 2.1 | 3.0+ | N/A |
3.2.4 | 3.2-maint | >= 0.69.9 < 1.0.0 | 3.1.x | 2.0 | 2.0+ | 4.6.1+ |
3.0.1 | 3.0-maint | >= 0.61.0 < 1.0.0 | 3.0.x | 2.1 | 3.0+ | N/A |
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
- Pomelo.EntityFrameworkCore.MySql.Json.Microsoft
- Pomelo.EntityFrameworkCore.MySql.Json.Newtonsoft
- Pomelo.EntityFrameworkCore.MySql.NetTopologySuite
Pomelo.EntityFrameworkCore.MySql
is tested at least against the latest 2 minor versions of MySQL
and MariaDB
. Older versions and other server implementations may be compatible (and likely are to a high degree) but are not officially supported or tested.
Currently supported versions are:
- MySQL 8.0
- MySQL 5.7
- MariaDB 10.5
- MariaDB 10.4
- MariaDB 10.3
Milestone | Status | Release Date |
---|---|---|
5.0.0 | In Development | TBA (see #1088) |
5.0.0-alpha.2 | Released | 2020-11-12 |
3.2.4 | Released | 2020-10-13 |
3.0.1 | Released | 2019-12-04 |
2.2.6 | Released | 2019-10-15 |
2.1.4 | Released | 2018-11-29 |
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>
We recommend to set utf8mb4
as your MySQL database default character set. This is already the server default in MySQL 8. The following statement will check the charset of the current database:
show variables like 'character_set_database';
Ensure that your .csproj
file contains the following reference:
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0-alpha.2" />
Add Pomelo.EntityFrameworkCore.MySql
to the services configuration in your the Startup.cs
file.
using System;
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
// Replace "YourNamespace" with the namespace of your application.
namespace YourNamespace
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Replace "YourDbContext" with the name of your own DbContext derived class.
services.AddDbContextPool<YourDbContext>(
dbContextOptions => dbContextOptions
.UseMySql(
// Replace with your connection string.
"server=localhost;user=root;password=1234;database=ef",
// Replace with your server version and type.
// For common usages, see pull request #1233.
new MySqlServerVersion(new Version(8, 0, 21)), // use MariaDbServerVersion for MariaDB
mySqlOptions => mySqlOptions
.CharSetBehavior(CharSetBehavior.NeverAppend))
// Everything from this point on is optional but helps with debugging.
.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 a MVC Application.
Refer to Microsoft's EF Core Documentation for detailed instructions and examples on using EF Core.
Use the EF Core tool to execute scaffolding commands:
dotnet ef dbcontext scaffold "Server=localhost;Database=ef;User=root;Password=123456;TreatTinyAsBoolean=true;" "Pomelo.EntityFrameworkCore.MySql"
One of the easiest ways to contribute is to report issues and participate in discussions. 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.