# EFResourceBuilderExtensions Methods

- Package: [Aspire.Hosting.EntityFrameworkCore](/reference/api/csharp/aspire.hosting.entityframeworkcore.md)
- Type: [EFResourceBuilderExtensions](/reference/api/csharp/aspire.hosting.entityframeworkcore/efresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `4`

Provides extension methods for adding EF Core migration management to projects.

## AddEFMigrations(IResourceBuilder<ProjectResource>, string, string)

- Name: `AddEFMigrations(IResourceBuilder<ProjectResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EFMigrationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.EntityFrameworkCore/EFResourceBuilderExtensions.cs#L56-L60)

Adds EF Core migration management for a specific DbContext type identified by name.

```csharp
public static class EFResourceBuilderExtensions
{
    public static IResourceBuilder<EFMigrationResource> AddEFMigrations(
        this IResourceBuilder<ProjectResource> builder,
        string name,
        string dbContextTypeName)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ProjectResource>`)
  The resource builder for the project.
- `name` (`string`)
  The name of the migration resource.
- `dbContextTypeName` (`string`)
  The fully qualified name of the DbContext type to manage migrations for.

## Returns

`IResourceBuilder<EFMigrationResource>` -- An EF migration resource builder for chaining additional configuration.

## Exceptions

- `InvalidOperationException` -- Thrown if migrations for this context type have already been added.

## Remarks

Multiple calls to this method with different context types are supported, allowing you to manage migrations for multiple DbContexts in the same project.

This overload is useful when the DbContext type is not available at compile time, such as when using runtime-discovered context types.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddEFMigrations(IResourceBuilder<ProjectResource>, string, string, Action<IResourceBuilder<DotnetToolResource>>)

- Name: `AddEFMigrations(IResourceBuilder<ProjectResource>, string, string, Action<IResourceBuilder<DotnetToolResource>>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EFMigrationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.EntityFrameworkCore/EFResourceBuilderExtensions.cs#L89-L93)

Adds EF Core migration management for a specific DbContext type identified by name.

```csharp
public static class EFResourceBuilderExtensions
{
    public static IResourceBuilder<EFMigrationResource> AddEFMigrations(
        this IResourceBuilder<ProjectResource> builder,
        string name,
        string dbContextTypeName,
        Action<IResourceBuilder<DotnetToolResource>>? configureToolResource)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ProjectResource>`)
  The resource builder for the project.
- `name` (`string`)
  The name of the migration resource.
- `dbContextTypeName` (`string`)
  The fully qualified name of the DbContext type to manage migrations for.
- `configureToolResource` (`Action<IResourceBuilder<DotnetToolResource>>`)
  Optional callback to configure the dotnet-ef tool resource used for migrations.

## Returns

`IResourceBuilder<EFMigrationResource>` -- An EF migration resource builder for chaining additional configuration.

## Exceptions

- `InvalidOperationException` -- Thrown if migrations for this context type have already been added.

## Remarks

Multiple calls to this method with different context types are supported, allowing you to manage migrations for multiple DbContexts in the same project.

This overload is useful when the DbContext type is not available at compile time, such as when using runtime-discovered context types.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddEFMigrations(IResourceBuilder<ProjectResource>, string)

- Name: `AddEFMigrations(IResourceBuilder<ProjectResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EFMigrationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.EntityFrameworkCore/EFResourceBuilderExtensions.cs#L107-L110)

Adds EF Core migration management for auto-detected DbContext types.

```csharp
public static class EFResourceBuilderExtensions
{
    public static IResourceBuilder<EFMigrationResource> AddEFMigrations(
        this IResourceBuilder<ProjectResource> builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ProjectResource>`)
  The resource builder for the project.
- `name` (`string`)
  The name of the migration resource.

## Returns

`IResourceBuilder<EFMigrationResource>` -- An EF migration resource builder for chaining additional configuration.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddEFMigrations(IResourceBuilder<ProjectResource>, string, Action<IResourceBuilder<DotnetToolResource>>)

- Name: `AddEFMigrations(IResourceBuilder<ProjectResource>, string, Action<IResourceBuilder<DotnetToolResource>>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EFMigrationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.EntityFrameworkCore/EFResourceBuilderExtensions.cs#L126-L129)

Adds EF Core migration management for auto-detected DbContext types.

```csharp
public static class EFResourceBuilderExtensions
{
    public static IResourceBuilder<EFMigrationResource> AddEFMigrations(
        this IResourceBuilder<ProjectResource> builder,
        string name,
        Action<IResourceBuilder<DotnetToolResource>>? configureToolResource)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ProjectResource>`)
  The resource builder for the project.
- `name` (`string`)
  The name of the migration resource.
- `configureToolResource` (`Action<IResourceBuilder<DotnetToolResource>>`)
  Optional callback to configure the dotnet-ef tool resource used for migrations.

## Returns

`IResourceBuilder<EFMigrationResource>` -- An EF migration resource builder for chaining additional configuration.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.
