You can install the driver by using the Windows installer.
After you receive the license key, add it to your connection strings to connect to the data source.
This tutorial shows how to connect a C# application to MySQL and MariaDB using Entity Framework Core with dotConnect for MySQL. You’ll create EF Core models using Entity Developer—a visual ORM builder and Scaffold-DbContext, build a console app, and perform CRUD operations through a structured database access layer.
Fully supports EF Core, Dapper, NHibernate, LinqConnect, and other technologies for efficient data management.
Conforms to the latest ADO.NET standards and innovations for seamless integration with .NET applications.
Offers many MySQL-specific features and fully supports all unique data types for accurate and complete data representation.
Provides robust security with support for SSL/SSH connections, connecting via proxy servers, embedded servers, and HTTP tunneling.
Features native integration with Visual Studio and complete design-time support for accelerated development.
Includes priority support, detailed documentation, and regular updates for continuous improvement.
You can start using dotConnect for MySQL immediately with a 30-day free trial. Choose one of the following installation options:
Once you have configured the database, you can move on to the next step: creating an EF Core model. You can do this in two ways: using Scaffold-DbContext or via Entity Developer.
Entity Developer allows you to visually design and generate EF Core models, making database application development faster, easier, and more efficient. If you don't have it already installed, close your Visual Studio instance, download Entity Developer, and install it following the on-screen instructions.
Follow the detailed illustrated guide to create your database model using Entity Developer. When this process is complete, the model you created opens, so you can work with it.
This guideline was designed with Visual Studio in mind. However, if you prefer VS Code, JetBrains Rider, or another similar tool, you can use ED as a standalone application to work with the models efficiently.
You can use Scaffold-DbContext to generate DbContext and entity classes for your database. Run the following command, replacing values with your actual credentials:
After you execute this command, the ModelContext file and the Models folder containing the table entity classes get generated.
Scaffold-DbContext "Host=127.0.0.1;Port=3306;User Id=TestUser;Password=TestPassword;Database=sakila;License Key=**********;" Devart.Data.MySql.EFCore -OutputDir Models
| Property | Meaning |
|---|---|
| Host | Hostname or IP address of the MySQL server |
| Port | Port number on which the MySQL server is listening |
| User Id | User ID used to authenticate with MySQL |
| Password | Password for the user ID |
| Database | Default database to be used after connecting |
| License key | Your license key (only required when using .NET Standard compatible assemblies) |
This section demonstrates how to connect to a MySQL database and retrieve the first 10 rows from the Actor table using EF Core. The SakilaModel DbContext is configured with a MySQL connection string in its OnConfiguring method. We will query the data and display it in the console for verification.
using MySQL_EF_Core;
namespace MySql_EF_Core
{
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new sakilaModel())
{
var actors = context.Actors
.Take(10)
.ToList();
Console.WriteLine("First 10 Actors:");
Console.WriteLine("---------------");
foreach (var actor in actors)
{
Console.WriteLine($"ID: {actor.ActorId}, Name: {actor.FirstName} {actor.LastName}, Last Update: {actor.LastUpdate:yyyy-MM-dd HH:mm:ss}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
}
}
Run the application. If everything is configured correctly, the console will display the first 10 records from the Actor table.

In this section, we insert a new test actor into the Actor table. EF Core's Add method stages the record, while SaveChanges persists it to the database.
using MySQL_EF_Core;
namespace MySql_EF_Core
{
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new sakilaModel())
{
var newActor = new Actor
{
FirstName = "Test",
LastName = "Actor",
LastUpdate = DateTime.Now
};
context.Actors.Add(newActor);
int rowsAffected = context.SaveChanges();
Console.WriteLine("Insert Result:");
Console.WriteLine("-------------");
Console.WriteLine($"Rows affected: {rowsAffected}");
Console.WriteLine($"Inserted Actor - ID: {newActor.ActorId}, Name: {newActor.FirstName} {newActor.LastName}, Last Update: {newActor.LastUpdate:yyyy-MM-dd HH:mm:ss}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
}
}
Run the application. The console will display the inserted record for verification purposes.

This section demonstrates how to update the test actor's first and last names. We retrieve the record by first name and last name, modify the properties, and call SaveChanges to store the modifications.
using MySQL_EF_Core;
namespace MySql_EF_Core
{
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new sakilaModel())
{
var actor = context.Actors
.FirstOrDefault(a => a.FirstName == "Test" && a.LastName == "Actor");
if (actor != null)
{
actor.FirstName = "Updated";
actor.LastName = "Star";
actor.LastUpdate = DateTime.Now;
int rowsAffected = context.SaveChanges();
Console.WriteLine("Update Result:");
Console.WriteLine("-------------");
Console.WriteLine($"Rows affected: {rowsAffected}");
Console.WriteLine($"Updated Actor - ID: {actor.ActorId}, Name: {actor.FirstName} {actor.LastName}, Last Update: {actor.LastUpdate:yyyy-MM-dd HH:mm:ss}");
}
else
{
Console.WriteLine("Test Actor not found.");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
}
}
After running the application, the console displays the updated record for verification.

Finally, we delete the test actor from the Actor table. The record is retrieved by first name and last name, removed using the Remove method, and SaveChanges commits the deletion.
using MySQL_EF_Core;
namespace MySql_EF_Core
{
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new sakilaModel())
{
var actor = context.Actors
.FirstOrDefault(a => a.FirstName == "Updated" && a.LastName == "Star");
if (actor != null)
{
context.Actors.Remove(actor);
int rowsAffected = context.SaveChanges();
Console.WriteLine("Delete Result:");
Console.WriteLine("-------------");
Console.WriteLine($"Rows affected: {rowsAffected}");
Console.WriteLine($"Deleted Actor - ID: {actor.ActorId}, Name: {actor.FirstName} {actor.LastName}");
}
else
{
Console.WriteLine("Test Actor not found.");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
}
}
After running the application, the console confirms the successful deletion.

In this tutorial, you learned how to integrate MySQL with Entity Framework Core using dotConnect for MySQL. This combination simplifies data access and enables clean, scalable development for .NET applications. With dotConnect's advanced capabilities and EF Core's familiar workflow, you are equipped to build robust solutions backed by MySQL.
License key parameter for a working connection.
License key value, then create a MySqlConnection instance with this string and call Open() for it inside a try-catch block to test and handle connection errors.
Protocol=SSL and specify the SSL CA Cert, SSL Cert, and SSL Key file paths in the connection string, then open the MySqlConnection connection to establish an encrypted SSL/TLS connection.
Scaffold-DbContext with a dotConnect connection string (including the License key) to generate the DbContext and entity classes.
I'm a technical content writer who loves turning complex topics — think SQL, connectors, and backend chaos–into content that actually makes sense (and maybe even makes you smile). I write for devs, data folks, and curious minds who want less fluff and more clarity. When I'm not wrangling words, you'll find me dancing salsa, or hopping between cities.