Integrates Entity Framework Core into an ABP application: defines AbpDbContext, registers repositories, writes custom EfCoreRepository classes, and sets up code-first migrations with DbMigrator.
Ships in abp-data-access. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Guidance for the EF Core data-access layer of an ABP solution. Types live in Volo.Abp.EntityFrameworkCore. The EF Core integration lives in the *.EntityFrameworkCore project; repository interfaces belong in the *.Domain project.
AbpDbContext<TDbContext> and mapping entities with ConfigureByConvention().AddAbpDbContext (AddDefaultRepositories, AddRepository).EfCoreRepository<TDbContext, TEntity, TKey>.IDbContextProvider<TDbContext> inside a repository.dotnet ef migrations) and running the DbMigrator console app.[UnitOfWork], IUnitOfWorkManager.Begin, SaveChangesAsync) — use manage-units-of-work.IHasConcurrencyStamp) — use handle-optimistic-concurrency.Derive from AbpDbContext<TDbContext> (which itself derives from EF Core's DbContext). Mark it with [ConnectionStringName] (from Volo.Abp.Data) so ABP resolves the right connection string.
[ConnectionStringName("Default")]
public class MyProjectDbContext : AbpDbContext<MyProjectDbContext>
{
public DbSet<Book> Books { get; set; }
public MyProjectDbContext(DbContextOptions<MyProjectDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder); // required — applies ABP conventions (audit/soft-delete/extra-props/concurrency) to entities already in the model
builder.Entity<Book>(b =>
{
b.ToTable("AppBooks");
b.ConfigureByConvention(); // applies ABP conventions (audit props, extra props, soft-delete, concurrency stamp)
b.Property(x => x.Name).IsRequired().HasMaxLength(128);
});
}
}
ConfigureByConvention() is an extension on EntityTypeBuilder from Volo.Abp.EntityFrameworkCore.Modeling. Always call base.OnModelCreating(builder) first.
Reusable modules expose a builder.ConfigureXxx() extension so a host DbContext can map the module's tables. Call them inside OnModelCreating:
builder.ConfigurePermissionManagement();
builder.ConfigureSettingManagement();
builder.ConfigureAuditLogging();
When you author a module, follow the same pattern: ship a <Module>DbContextModelCreatingExtensions class with a Configure<Module>(this ModelBuilder builder) extension.
Register the DbContext and repositories in your *.EntityFrameworkCore module's ConfigureServices via AddAbpDbContext<TDbContext>:
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<MyProjectDbContext>(options =>
{
// Register a default IRepository<TEntity, TKey> for every aggregate root
options.AddDefaultRepositories(includeAllEntities: true);
// Or override a single entity with a custom repository implementation
options.AddRepository<Book, EfCoreBookRepository>();
});
}
AddDefaultRepositories(includeAllEntities: true) also registers repositories for entities that are not aggregate roots.AddDefaultRepository<TEntity>() registers just one.AddRepository<TEntity, TRepository>() binds a custom repository.Declare the interface in the Domain project:
public interface IBookRepository : IRepository<Book, Guid>
{
Task<List<Book>> GetListByAuthorAsync(Guid authorId);
}
IRepository is the right base inside a final application. For a reusable module published for other apps, extend IBasicRepository<Book, Guid> (or IReadOnlyBasicRepository) instead, so consumers aren't coupled to a provider's IQueryable (see use-abp-repositories).
Implement in the EntityFrameworkCore project by deriving from EfCoreRepository<TDbContext, TEntity, TKey>:
public class EfCoreBookRepository
: EfCoreRepository<MyProjectDbContext, Book, Guid>, IBookRepository
{
public EfCoreBookRepository(IDbContextProvider<MyProjectDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task<List<Book>> GetListByAuthorAsync(Guid authorId)
{
var dbSet = await GetDbSetAsync();
return await dbSet.Where(b => b.AuthorId == authorId).ToListAsync();
}
}
GetQueryableAsync() → IQueryable<TEntity> for LINQ composition.GetDbSetAsync() → the raw DbSet<TEntity>.GetDbContextAsync() → the TDbContext when you need Set<TOther>(), Database, etc.var queryable = await GetQueryableAsync();
var query = queryable.Where(b => b.Name.Contains(filter));
Prefer these async accessors over old sync members (DbSet, DbContext) — the sync ones are [Obsolete].
IDbContextProvider<TDbContext> resolves the active DbContext for the current unit of work (handling transactions/connection-string routing). It lives in Volo.Abp.EntityFrameworkCore, so only the EntityFrameworkCore project should touch it — keep DbContext access inside a custom repository, not a domain/application service. Injecting it into the Domain or Application layer forces those layers to reference EF Core, which breaks the layering and the encapsulation the repository pattern exists to provide.
Declare the repository interface in the Domain project (no EF Core types leak out):
public interface IBookRepository : IRepository<Book, Guid>
{
Task DoAsync();
}
Implement it in the EntityFrameworkCore project, where IDbContextProvider<TDbContext> is available (EfCoreRepository already gets one via its base constructor, so call GetDbContextAsync() directly):
public class EfCoreBookRepository
: EfCoreRepository<MyProjectDbContext, Book, Guid>, IBookRepository
{
public EfCoreBookRepository(IDbContextProvider<MyProjectDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task DoAsync()
{
var dbContext = await GetDbContextAsync();
// use dbContext.Books ...
}
}
Domain/application services then depend on IBookRepository, staying free of any EF Core reference.
In a layered ABP solution, migrations live in a dedicated project (typically *.EntityFrameworkCore or a separate *.DbMigrations) and a *.DbMigrator console app applies them + seeds data.
Add a migration and update the database from the project holding the DbContext:
dotnet ef migrations add Added_Books
dotnet ef database update
Run the migrator console app to apply pending migrations and run data seeders (recommended for CI/deploy):
dotnet run --project src/MyProject.DbMigrator
The DbMigrator uses IDataSeeder to seed initial data (admin user, permissions, etc.) after migrating.
The startup template ships SQL Server (Volo.Abp.EntityFrameworkCore.SqlServer + AbpEntityFrameworkCoreSqlServerModule + UseSqlServer()). To switch, do three edits in the *.EntityFrameworkCore project, then regenerate migrations.
1. Swap the NuGet package (use the same version as the SqlServer one you remove):
| DBMS | NuGet package | ABP module ([DependsOn]) | UseXxx() call |
|---|---|---|---|
| MySQL | Volo.Abp.EntityFrameworkCore.MySQL | AbpEntityFrameworkCoreMySQLModule | UseMySQL() |
| MySQL (Pomelo) | Volo.Abp.EntityFrameworkCore.MySQL.Pomelo | AbpEntityFrameworkCoreMySQLPomeloModule | UseMySQL() |
| PostgreSQL | Volo.Abp.EntityFrameworkCore.PostgreSql | AbpEntityFrameworkCorePostgreSqlModule | UseNpgsql() |
| Oracle (official) | Volo.Abp.EntityFrameworkCore.Oracle | AbpEntityFrameworkCoreOracleModule | UseOracle() |
| Oracle (Devart) | Volo.Abp.EntityFrameworkCore.Oracle.Devart | AbpEntityFrameworkCoreOracleDevartModule | UseOracle() |
| SQLite | Volo.Abp.EntityFrameworkCore.Sqlite | AbpEntityFrameworkCoreSqliteModule | UseSqlite() |
2. Replace the module dependency in your *EntityFrameworkCoreModule: drop typeof(AbpEntityFrameworkCoreSqlServerModule) from [DependsOn], add the new one, and swap the matching using (e.g. using Volo.Abp.EntityFrameworkCore.PostgreSql;).
3. Replace the UseXxx() call. The UseSqlServer() / UseMySQL() / UseNpgsql() / UseOracle() / UseSqlite() extensions on AbpDbContextOptions live in Volo.Abp.EntityFrameworkCore (they delegate to the AbpDbContextConfigurationContext extension of the same name, which routes ExistingConnection vs ConnectionString and sets SplitQuery):
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpDbContextOptions>(options =>
{
options.UseNpgsql(); // was options.UseSqlServer();
});
}
Change the same call in *DbContextFactory.cs (the design-time factory used by dotnet ef) — there it's on DbContextOptionsBuilder, e.g. .UseNpgsql(configuration.GetConnectionString("Default")).
Provider-specific notes from the docs:
UsePostgreSql() is [Obsolete] — use UseNpgsql(). Enable AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true) in PreConfigureServices and in the design-time factory.Volo.Abp.EntityFrameworkCore.Oracle (ODP.NET driver) and Volo.Abp.EntityFrameworkCore.Oracle.Devart (Devart driver). Pick one; both expose UseOracle(). Requires Oracle v12.2+ (128-byte identifier limit), and long string columns may need long/clob conversion migrations.UseMySQL() extension — Volo.Abp.EntityFrameworkCore.MySQL runs on the MySql.EntityFrameworkCore driver, while Volo.Abp.EntityFrameworkCore.MySQL.Pomelo runs on the Pomelo driver and auto-detects the ServerVersion (via ServerVersion.AutoDetect), so you don't pass one.Regenerate migrations. EF Core migrations contain provider-specific SQL, so the existing ones won't apply on a new provider. Also swap the appsettings.json connection strings (in .DbMigrator, .Web, etc.) to the new provider's format.
Migrations folder under the *.EntityFrameworkCore project, rebuild, add a fresh Initial migration (dotnet ef migrations add Initial), then run the *.DbMigrator to create the database and seed.*.EntityFrameworkCore project references Volo.Abp.EntityFrameworkCore; the DbContext derives from AbpDbContext<TDbContext> and carries [ConnectionStringName].OnModelCreating calls base.OnModelCreating(builder) and ConfigureByConvention() on each mapped entity.IRepository<Book, Guid> (or your IBookRepository) resolves after AddAbpDbContext registration — confirm the app boots and the repository is available.dotnet ef migrations add ... generates a migration; dotnet run --project src/MyProject.DbMigrator applies pending migrations and runs seeders without error.Volo.Abp.EntityFrameworkCore — repository interfaces stay EF-free.base.OnModelCreating(builder) — without it AbpDbContext can't apply its property/value-converter conventions (audit, soft-delete, extra properties, concurrency stamp) to the entities in the model. Call it first. It configures entities already in the model; ABP module entities (Identity, Permission Management, etc.) are still mapped separately by each module's own builder.ConfigureXxx() extension.DbSet/DbContext members — they are [Obsolete]; use the async GetDbSetAsync() / GetDbContextAsync() / GetQueryableAsync() accessors.IDbContextProvider<TDbContext> into a Domain or Application service — it forces those layers to reference EF Core and breaks layering. Keep DbContext access inside a custom repository in the EntityFrameworkCore project.AddDefaultRepositories() without includeAllEntities: true — non-aggregate-root entities won't get a default repository.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
abp, entity-framework-core, dbcontext, migrations, repository
/abp-data-access:ef-core-integrationfrom abp-data-access
npx claudepluginhub abpframework/abp-skills --plugin abp-data-access9 skills in this plugin
/apply-data-filtersWork with ABP data filters — the built-in ISoftDelete and IMultiTenant filters, toggling them via IDataFilter scopes, changing default states, and defining custom global query filters for EF Core or MongoDB. USE FOR: reading/writing soft-deleted or cross-tenant data with IDataFilter.Disable/Enable, checking IsEnabled, HardDeleteAsync, changing AbpDataFilterOptions defaults, defining a custom marker-interface filter, wiring it in EF Core (ShouldFilterEntity/CreateFilterExpression/HasAbpQueryFilter) or MongoDB (MongoDbRepositoryFilterer/FilterQueryable). DO NOT USE FOR: switching the active tenant context via ICurrentTenant.Change (that is the multi-tenancy concern); defining a DbContext/repositories or EF Core migrations (use ef-core-integration); MongoDB DbContext/repository setup (use mongodb-integration); transaction/UOW boundaries (use manage-units-of-work); optimistic concurrency (use handle-optimistic-concurrency).
/configure-connection-stringsConfigure ABP connection strings for modular and multi-tenant apps — the Default connection, per-module databases, grouping modules into one database, and per-tenant database routing. USE FOR: setting the Default connection, giving a module its own database with a named entry, binding a DbContext via [ConnectionStringName], mapping several modules to one DB with AbpDbConnectionOptions.Databases, routing a tenant to its own database, customizing IConnectionStringResolver. DO NOT USE FOR: EF Core DbContext registration/model config (use ef-core-integration), MongoDB client/database setup (use mongodb-integration), creating tenants or the tenant store (use configure-multi-tenancy), unit-of-work/transaction handling (use manage-units-of-work).
/handle-optimistic-concurrencyEnable and handle ABP optimistic concurrency control so concurrent updates to the same record are detected and rejected. USE FOR: enabling concurrency with IHasConcurrencyStamp/ConcurrencyStamp, deriving from aggregate root base classes to get it for free, flowing the stamp through output and update DTOs, handling AbpDbConcurrencyException when two users update the same record. DO NOT USE FOR: EF-Core-specific mapping/change tracking (use ef-core-integration), MongoDB provider setup (use mongodb-integration), unit-of-work flush/transaction control (use manage-units-of-work), general validation/error surfacing (use handle-validation-and-errors).
/manage-units-of-workControl ABP's Unit of Work — transaction and connection scope, explicit UOW scopes, the [UnitOfWork] attribute, and mid-scope SaveChangesAsync. USE FOR: starting explicit scopes with IUnitOfWorkManager.Begin, applying [UnitOfWork], choosing transactional vs non-transactional boundaries, calling SaveChangesAsync mid-scope, working with nested/RequiresNew/reserved scopes, reading IUnitOfWorkManager.Current, using OnCompleted/CompleteAsync/RollbackAsync. DO NOT USE FOR: defining a DbContext or repositories, or EF Core migrations (use ef-core-integration); MongoDB DbContext/repositories (use mongodb-integration); soft-delete/multi-tenant/custom query filters (use apply-data-filters); optimistic concurrency stamps (use handle-optimistic-concurrency); connection-string resolution (use configure-connection-strings).
/mongodb-integrationIntegrate MongoDB into an ABP application: AbpMongoDbContext, collection mapping, AddMongoDbContext registration, and custom Mongo repositories. USE FOR: defining an AbpMongoDbContext, mapping collections with [MongoCollection]/CreateModel, registering via AddMongoDbContext, wiring AddDefaultRepositories/AddRepository, writing custom MongoDbRepository classes, reaching the DbContext via IMongoDbContextProvider, using GetCollectionAsync/GetAggregateAsync. DO NOT USE FOR: consuming standard IRepository methods (use-abp-repositories); Entity Framework Core integration, DbContext model builder, or code-first migrations (use ef-core-integration); controlling transaction/UOW boundaries (use manage-units-of-work); soft-delete/multi-tenant/custom query filters or MongoDbRepositoryFilterer (use apply-data-filters); optimistic concurrency (use handle-optimistic-concurrency); connection-string configuration (use configure-connection-strings); seeding data via IDataSeeder (use seed-application-data).
/query-with-dapperRun raw SQL via Dapper inside an ABP repository for hot-path read/aggregate queries while sharing ABP's unit of work, connection, and transaction. USE FOR: complex or slow queries where EF Core's generated SQL is too slow, hand-written SQL you want full control over, deriving from a DbContext-based DapperRepository and using GetDbConnectionAsync/GetDbTransactionAsync to stay in the current unit of work. DO NOT USE FOR: standard CRUD/LINQ/change tracking/migrations (use ef-core-integration), MongoDB queries (use mongodb-integration), unit-of-work configuration itself (use manage-units-of-work), connection string routing (use configure-connection-strings).
Other plugins' skills for the same job