Documentation Home
Connectors and APIs Manual
Download this Manual

4.7.2 Entity Framework Core Support

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 4.4 Connector/NET Versions and Entity Framework Core Support

Connector/NET EF Core 6.0 (Preview) EF Core 5.0 EF Core 3.1.1
8.0.23 .NET 5 (.NET 6 when released) .NET Standard 2.1 (feature set is equivalent to EF Core 3.1.1) .NET Standard 2.0
8.0.20 to 8.0.22 Not supported Not supported .NET Standard 2.0

To continue using EF Core 2.1, select Connector/NET versions 8.0.13 to 8.0.19 only. The requirements are .NET Standard 2.0 or .NET Framework 4.6.1 and later.

In this section:

General Requirements for EF Core Support

Configuration with MySQL

To use Entity Framework Core with a MySQL database, do the following:

  1. Install the NuGet package.

    When you install either the MySql.EntityFrameworkCore or MySql.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.

  2. In the class that derives from the DbContext class, override the OnConfiguring method to set the MySQL data provider with UseMySQL. 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 4.5 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.