Documentation Home
MySQL Connector/NET Developer Guide
Related Documentation Download this Manual

9.2 Entity Framework Core Support

MySQL Connector/NET integrates support for Entity Framework Core (EF Core), but also offers support for Entity Framework 6 (EF6). 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 requirements.

Table 9.2 Supported versions of Entity Framework Core

Connector/NET EF Core 1.1 EF Core 2.0 EF Core 2.1
6.10.4 .NET Core 1.3 or .NET Framework 4.5.2 (and later) Not supported Not supported
6.10.5 to 6.10.7 .NET Core 1.3 or .NET Framework 4.5.2 (and later) .NET Core 2.0 only (.NET Framework is not supported)

Scaffolding is not supported

Not supported
6.10.8 .NET Core 1.3 or .NET Framework 4.5.2 .NET Core 2.0 or .NET Framework 4.6.1 (and later) Not supported
8.0.11 to 8.0.12 .NET Core 1.6 or .NET Framework 4.5.2 (and later) .NET Core 2.0 only (.NET Framework is not supported)

Scaffolding is not supported

Not supported

In this section:

Requirements for EF Core Support

Configuration with MySQL

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

  1. Install the MySql.Data.EntityFrameworkCore NuGet package.

    For EF Core 1.1 only: If you plan to scaffold a database, install the MySql.Data.EntityFrameworkCore.Design NuGet package as well.

    All packages will install the additional packages required to run your application. 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 9.3 Maximum Length of strings used with EF Core

Data TypeMaximum Length.NET Type
CHAR255string
BINARY255byte[]
VARCHAR, VARBINARY65,535string, byte[]
TINYBLOB, TINYTEXT255byte[]
BLOB, TEXT65,535byte[]
MEDIUMBLOB, MEDIUMTEXT16,777,215byte[]
LONGBLOB, LONGTEXT4,294,967,295byte[]
ENUM65,535string
SET65,535string

For additional information about the storage requirements of the string types, see String Type Storage Requirements.


User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
Sign Up Login You must be logged in to post a comment.