Share via


EntityFrameworkServiceCollectionExtensions.AddEntityFramework Method

Definition

Caution

AddEntityFramework is no longer functional. Use AddEntityFrameworkSqlServer, AddEntityFrameworkSqlite, etc. instead.

This method is no longer functional. Call a provider-specific method such as AddEntityFrameworkSqlServer, AddEntityFrameworkSqlite, etc. instead.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddEntityFramework (this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection);
[System.Obsolete("AddEntityFramework is no longer functional. Use AddEntityFrameworkSqlServer, AddEntityFrameworkSqlite, etc. instead.", true)]
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddEntityFramework (this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection);
static member AddEntityFramework : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection
[<System.Obsolete("AddEntityFramework is no longer functional. Use AddEntityFrameworkSqlServer, AddEntityFrameworkSqlite, etc. instead.", true)>]
static member AddEntityFramework : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddEntityFramework (serviceCollection As IServiceCollection) As IServiceCollection

Parameters

serviceCollection
IServiceCollection

The service collection.

Returns

Always throws NotSupportedException.

Attributes

Exceptions

Always throws NotSupportedException.

Examples

public void ConfigureServices(IServiceCollection services) 
{
    var connectionString = "connection string to database";

    services.AddDbContext<MyContext>(options => options.UseSqlServer(connectionString)); 
}

Remarks

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

The database you are using will also define extension methods that can be called on the returned IServiceCollection to register the services required by the database. For example, when using Microsoft.EntityFrameworkCore.SqlServer you would call collection.AddEntityFrameworkSqlServer().

For derived contexts to be registered in the IServiceProvider and resolve their services from the IServiceProvider you must chain a call to the AddDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime) method on the returned IServiceCollection.

Applies to