Microsoft SQL Server EF Core Database Provider
This database provider allows Entity Framework Core to be used with Microsoft SQL Server (including Azure SQL and Azure Synapse Analytics). The provider is maintained as part of the Entity Framework Core Project.
Install
Install the Microsoft.EntityFrameworkCore.SqlServer NuGet package.
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
Note
The provider references Microsoft.Data.SqlClient (not System.Data.SqlClient). If your project takes a direct dependency on SqlClient, make sure it references the Microsoft.Data.SqlClient package.
Tip
The Microsoft.Data.SqlClient package ships more frequently than the EF Core provider. If you would like to take advantage of new features and bug fixes, you can add a direct package reference to the latest version of Microsoft.Data.SqlClient.
Warning
The async implementation of Microsoft.Data.SqlClient unfortunately has some known issues (e.g. #593, #601, and others). If you're seeing unexpected performance problems, try using sync command execution instead, especially when dealing with large text or binary values.
Usage
Starting with EF 9, it's recommended to use UseAzureSql
and UseAzureSynapse
to specify that you're connecting to Azure SQL or Azure Synapse Analytics specifically, and UseSqlServer
to specify that you're connecting to on-premises SQL Server; doing so allows the provider to optimize for and properly support these platforms. It's also recommended to use UseCompatibilityLevel
method to specify the compatibility level so that the generated SQL is compatible and/or uses the latest possible features.
Note
UseAzureSql and UseAzureSynapse methods were introduced in EF Core 9.0.
Supported Database Engines
- Microsoft SQL Server (2012 onwards)
- Azure SQL
- Azure Synapse Analytics