Skip to main content
All docs
V25.1
.NET 8.0+

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Switch EF Core Connection from SQL Server to a Different Database Provider

  • 4 minutes to read

The XAF Wizard creates applications that use the Microsoft SQL Server. To use a different database provider, modify your XAF solution. Use the EFCoreProvider parameter to specify the provider type.

#PostgreSQL

  1. Install the Npgsql.EntityFrameworkCore.PostgreSQL package. Note that the version of the Microsoft.EntityFrameworkCore package reference must be compatible with the Entity Framework version that your solution uses.

  2. Change your application’s connection string.

    "ConnectionStrings": {
        "ConnectionString": "EFCoreProvider=PostgreSql;Host=localhost;Database=my_db;Username=postgres;Password=qwerty",
    
  3. If you use migrations, change the MySolutionDesignTimeDbContextFactory.ConnectionString property as follows:

    public class MySolutionDesignTimeDbContextFactory : DesignTimeDbContextFactory<MySolutionEFCoreDbContext> {
        protected override string ConnectionString  => 
            "EFCoreProvider=PostgreSql;Host=localhost;Database=my_db2;Username=postgres;Password=qwerty";
    }
    

#MySQL

  1. Install the Pomelo.EntityFrameworkCore.MySql package. Note that the version of the Microsoft.EntityFrameworkCore package reference must be compatible with the Entity Framework version that your solution uses.

  2. Change your application’s connection string.

    "ConnectionStrings": {
        "ConnectionString": "EFCoreProvider=MySQL; server=localhost; database=MySQLSolution; user=root; password=qwerty",
    
  3. If you use migrations, change the MySolutionDesignTimeDbContextFactory.ConnectionString property as follows:

    public class MySQLSolutionDesignTimeDbContextFactory : DesignTimeDbContextFactory<MySQLSolutionEFCoreDbContext> {
        protected override string ConnectionString  => 
            "EFCoreProvider=MySQL; server=localhost; database=MySQLSolution; user=root; password=qwerty"
    }
    

#Supported Database Providers

This section contains a list of EF Core providers supported by XAF applications. Use the EFCoreProvider parameter in the connection string to specify the database provider type used in your application.

Database Provider NuGet package EFCoreProvider property value
Microsoft SQL Server Microsoft.EntityFrameworkCore.SqlServer SqlServer
Microsoft SQL Azure Microsoft.EntityFrameworkCore.SqlServer SqlServer
MySQL Pomelo.EntityFrameworkCore.MySql MySQL
PostgreSQL Npgsql.EntityFrameworkCore.PostgreSQL PostgreSQL
Oracle Oracle.EntityFrameworkCore Oracle
Firebird FirebirdSql.EntityFrameworkCore.Firebird Firebird
SQLite Microsoft.EntityFrameworkCore.Sqlite SQLite
InMemory Microsoft.EntityFrameworkCore.InMemory InMemory

To configure an application with a non-listed database provider, follow these steps:

  1. Install the relevant EFCore provider for your database. Refer to the following topic for a list of available EF Core providers: Database Providers.
  2. Change your application’s connection string. Do not specify the EFCoreProvider parameter.

    "ConnectionStrings": {
        "ConnectionString": "<write your connection string here>",
    
  3. If you use migrations, change the MySolutionDesignTimeDbContextFactory.CreateDbContext method to use your database provider and the updated connection string. Call the appropriate extension method to set up the provider and connection string: options.UseYourConnectionProvider(connectionString). This method and its parameters can be found in the official documentation for the EFCore provider being used.

    public class MySolutionDesignTimeDbContextFactory : DesignTimeDbContextFactory<MySolutionDbContext> {
        public MySolutionDbContext CreateDbContext(string[] args) {
            var optionsBuilder = new DbContextOptionsBuilder<MySolutionDbContext>();
            optionsBuilder.UseYourConnectionProvider(connectionString);
            optionsBuilder.UseChangeTrackingProxies();
            optionsBuilder.UseObjectSpaceLinkProxies();
            return new MySolutionDbContext(optionsBuilder.Options);
        }
    
  4. Change the following files to use your database provider:

    public class Startup {
        public void ConfigureServices(IServiceCollection services) {
            //...
            builder.ObjectSpaceProviders
                .AddSecuredEFCore().WithDbContext<MySolution.Module.BusinessObjects.MySolutionDbContext>((serviceProvider, options) => {
                    options.UseYourConnectionProvider(connectionString);
                    options.UseChangeTrackingProxies();
                    options.UseObjectSpaceLinkProxies();
                })
    

#SQLite and Other File-Based Databases

We do not recommend using SQLite with XAF in production scenarios with large amounts of data. SQLite is a file-based database that, due to its design, is inferior in performance and other features to powerful distributed server-based RDBMSs such as SQL Server, Oracle, MySQL, or PostgreSQL (used by the majority of our customers). If you experience performance issues with SQLite and other file-based databases (even with our Server Mode data sources), we cannot offer any suitable solutions other than switching to another RDBMS.

We can only recommend that our customers use SQLite for demo/testing purposes or simple applications that do not have many records. NOTE: as a developer or tester, you can also use the databases that can be installed with Visual Studio: Microsoft SQL Server Express or LocalDB databases (a free edition of SQL Server, ideal for development and production for desktop, web, and small server applications).

For XPO-based applications, refer to the following topic to learn how to connect these applications to different database providers: Database Systems Supported by XPO.

See Also