MySQL Connector/NET integrates support for Entity Framework Core (EF Core). The requirements and configuration of EF Core depend on the version of Connector/NET installed and the features that you require. Use the table that follows to evaluate the minimum requirements.
Table 7.2 Connector/NET Versions and Entity Framework Core Support
Connector/NET | EF Core 9.0 | EF Core 8.0 | EF Core 7.0 | EF Core 6.0 |
---|---|---|---|---|
9.2.0 | .NET 9, .NET 8 | Not supported | Not supported | |
9.1.0 | .NET 9 preview, .NET 8, .NET 6 | Not supported | .NET 6 | |
9.0.0 | .NET 8, .NET 6 | Not supported | .NET 6 | |
8.3.0 and 8.4.0 | Not supported | .NET 8, .NET 7, .NET 6 | .NET 7, .NET 6 | .NET 6 |
8.2.0 | Not supported | .NET 8 preview | .NET 7 | .NET 6 |
8.1.0 | Not supported | Not supported | .NET 7 | .NET 6 |
8.0.33 | Not supported | Not supported | .NET 7 | .NET 6 |
8.0.28 | Not supported | Not supported | Not supported | .NET 6 |
8.0.23 to 8.0.27 | Not supported | Not supported | Not supported | EF Core 6.0 preview |
In this section:
General Requirements for EF Core Support
Server version: MySQL 8.0 or later
Entity Framework Core packages (replace
n
with a valid number to complete the full version of the package):MySql.EntityFrameworkCore
8.0.n
+MySQL8.n
MySql.EntityFrameworkCore
6.0.n
+MySQL8.n
An implementation of .NET Standard or .NET Framework that is supported by Connector/NET (see Table 7.2, “Connector/NET Versions and Entity Framework Core Support”)
.NET | .NET Core SDK
.NET 8.0 for all supported platforms: https://dotnet.microsoft.com/es-es/download/dotnet/8.0
.NET 6.0 for all supported platforms: https://dotnet.microsoft.com/download/dotnet/6.0
.NET Core for Microsoft Windows: https://www.microsoft.com/net/core#windowscmd
.NET Core for Linux: https://www.microsoft.com/net/core#linuxredhat
.NET Core for macOS: https://www.microsoft.com/net/core#macos
Optional: Microsoft Visual Studio 2017, 2019, 2022, or Code
NoteFor the minimum version of Visual Studio to use with Connector/NET, see Table 2.1, “Connector/NET Requirements for Related Products”.
Configuration with MySQL
To use Entity Framework Core with a MySQL database, do the following:
Install the NuGet package.
When you install either the
MySql.EntityFrameworkCore
orMySql.Data.EntityFrameworkCore
package, all of the related packages required to run your application are installed for you. For instructions on adding a NuGet package, see the relevant Microsoft documentation.In the class that derives from the
DbContext
class, override theOnConfiguring
method to set the MySQL data provider withUseMySQL
. The following example shows how to set the provider using a generic connection string in C#.protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings. optionsBuilder.UseMySQL("server=localhost;database=library;user=user;password=password"); }
Limitations
The Connector/NET implementation of EF Core has the following limitations:
Memory-Optimized Tables is not supported.
Maximum String Length
The following table shows the maximum length of string types supported by the Connector/NET implementation of EF Core. Length values are in bytes for nonbinary and binary string types, depending on the character set used.
Table 7.3 Maximum Length of strings used with Entity Framework Core
Data Type | Maximum Length | .NET Type |
---|---|---|
CHAR |
255 | string |
BINARY |
255 | byte[] |
VARCHAR , VARBINARY |
65,535 | string , byte[] |
TINYBLOB , TINYTEXT |
255 | byte[] |
BLOB , TEXT |
65,535 | byte[] |
MEDIUMBLOB , MEDIUMTEXT |
16,777,215 | byte[] |
LONGBLOB , LONGTEXT |
4,294,967,295 | byte[] |
ENUM |
65,535 | string |
SET |
65,535 | string |
For additional information about the storage requirements of the string types, see String Type Storage Requirements.