Extension methods to make working with EF Core easier.
- ApplyAllConfigurationsFromCurrentAssembly
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);
}
}
}
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