SqlServerServiceCollectionExtensions.AddEntityFrameworkSqlServer(IServiceCollection) SqlServerServiceCollectionExtensions.AddEntityFrameworkSqlServer(IServiceCollection) SqlServerServiceCollectionExtensions.AddEntityFrameworkSqlServer(IServiceCollection) Method

Definition

Adds the services required by the Microsoft SQL Server database provider for Entity Framework to an IServiceCollection. You use this method when using dependency injection in your application, such as with ASP.NET. For more information on setting up dependency injection, see http://go.microsoft.com/fwlink/?LinkId=526890.

You only need to use this functionality when you want Entity Framework to resolve the services it uses from an external dependency injection container. If you are not using an external dependency injection container, Entity Framework will take care of creating the services it requires.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddEntityFrameworkSqlServer (this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection);
static member AddEntityFrameworkSqlServer : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddEntityFrameworkSqlServer (serviceCollection As IServiceCollection) As IServiceCollection

Parameters

Returns

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

Examples


           public void ConfigureServices(IServiceCollection services)
           {
               var connectionString = "connection string to database";
  
               services
                   .AddEntityFrameworkSqlServer()
                   .AddDbContext<MyContext>((serviceProvider, options) =>
                       options.UseSqlServer(connectionString)
                              .UseInternalServiceProvider(serviceProvider));
           }

            public void ConfigureServices(IServiceCollection services)
            {
                var connectionString = "connection string to database";
  
                services
                    .AddEntityFrameworkSqlServer()
                    .AddDbContext<MyContext>((serviceProvider, options) =>
                        options.UseSqlServer(connectionString)
                               .UseInternalServiceProvider(serviceProvider));
            }

             public void ConfigureServices(IServiceCollection services)
             {
                 var connectionString = "connection string to database";
  
                 services
                     .AddEntityFrameworkSqlServer()
                     .AddDbContext<MyContext>((serviceProvider, options) =>
                         options.UseSqlServer(connectionString)
                                .UseInternalServiceProvider(serviceProvider));
             }

Applies to