Search Results for

    Show / Hide Table of Contents

    Class MySQLServiceCollectionExtensions

    MySQL extension class for Microsoft.Extensions.DependencyInjection.IServiceCollection.

    Inheritance
    System.Object
    MySQLServiceCollectionExtensions
    Namespace: MySql.EntityFrameworkCore.Extensions
    Assembly: MySql.EntityFrameworkCore.dll
    Version: 9.3.0
    Syntax
    public static class MySQLServiceCollectionExtensions

    Methods

    AddEntityFrameworkMySQL(IServiceCollection)

    Adds the services required by the MySQL database provider for Entity Framework to an Microsoft.Extensions.DependencyInjection.IServiceCollection.

    Warning: Do not call this method by mistake. Instead, it is more likely that you need to call AddMySQLServer<TContext>(IServiceCollection, String, Action<MySQLDbContextOptionsBuilder>, Action<DbContextOptionsBuilder>).

    Calling this method is no longer necessary when building most applications, including those that use dependency injection in ASP.NET or elsewhere. It is only needed when building the internal service provider for use with the Microsoft.EntityFrameworkCore.DbContextOptionsBuilder.UseInternalServiceProvider(System.IServiceProvider) method. This is not recommend other than for some advanced scenarios.

    Declaration
    public static IServiceCollection AddEntityFrameworkMySQL(this IServiceCollection services)
    Parameters
    Type Name Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection services

    The Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.

    Returns
    Type Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection

    The same service collection so that multiple calls can be chained.

    AddMySQLServer<TContext>(IServiceCollection, String, Action<MySQLDbContextOptionsBuilder>, Action<DbContextOptionsBuilder>)

    Registers the given Entity Framework Microsoft.EntityFrameworkCore.DbContext as a service in the Microsoft.Extensions.DependencyInjection.IServiceCollection and configures it to connect to a MySQL database.

    This method is a shortcut for configuring a Microsoft.EntityFrameworkCore.DbContext to use MySQL.

    Use this method when using dependency injection in your application, such as with ASP.NET Core. For applications that don't use dependency injection, consider creating Microsoft.EntityFrameworkCore.DbContext instances directly with its constructor. The Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder) method can then be overridden to configure the MySQL provider and connection string.

    To configure the Microsoft.EntityFrameworkCore.DbContextOptions`1 for the context, either override the Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder) method in your derived context, or supply an optional action to configure the Microsoft.EntityFrameworkCore.DbContextOptions for the context.

    See Using DbContext with dependency injection for more information.

    Declaration
    public static IServiceCollection AddMySQLServer<TContext>(this IServiceCollection serviceCollection, string connectionString, Action<MySQLDbContextOptionsBuilder> sqlServerOptionsAction = null, Action<DbContextOptionsBuilder> optionsAction = null)
        where TContext : DbContext
    Parameters
    Type Name Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection

    The Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.

    System.String connectionString

    The connection string of the database to connect to.

    System.Action<MySQLDbContextOptionsBuilder> sqlServerOptionsAction

    An optional action to enable additional MySQL server-specific configuration.

    System.Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction

    An optional action to configure the Microsoft.EntityFrameworkCore.DbContextOptions for the context.

    Returns
    Type Description
    Microsoft.Extensions.DependencyInjection.IServiceCollection

    The same service collection so that multiple calls can be chained.

    Type Parameters
    Name Description
    TContext

    The type of context to be registered.

    In This Article
    • Methods
      • AddEntityFrameworkMySQL(IServiceCollection)
      • AddMySQLServer<TContext>(IServiceCollection, String, Action<MySQLDbContextOptionsBuilder>, Action<DbContextOptionsBuilder>)
    Back to top Copyright © 2021, 2025, Oracle and/or its affiliates.