EFCore.Extensions icon indicating copy to clipboard operation
EFCore.Extensions copied to clipboard

Extension methods to make working with EF Core easier.

NuGetNuGet Build Status

EFCore.Extensions

Extension methods to make working with EF Core easier.

  • ApplyAllConfigurationsFromCurrentAssembly

Sample Usage

using Ardalis.EFCore.Extensions;
using Microsoft.EntityFrameworkCore

namespace YourNamespace
{
    public class AppDbContext : DbContext
    {
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
        
            // ApplyConfiguration calls must follow base.OnModelCreating()
            builder.ApplyAllConfigurationsFromCurrentAssembly();

			// Apply configurations in a different assembly - just reference a type in that assembly
			modelBuilder.ApplyAllConfigurationsFromCurrentAssembly(typeof(ToDoItem).Assembly);
        }
    }
}

To Test, Run Migrations

A sample migration script to add migrations to a Clean Architecture solution template is shown here (run from the solution root):

dotnet ef migrations add Initial -p .\src\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj -s .\src\CleanArchitecture.Web\CleanArchitecture.Web.csproj -o Data/Migrations